]> granicus.if.org Git - clang/commitdiff
[format strings] correctly suggest correct type for '%@' specifiers. Fixes <rdar...
authorTed Kremenek <kremenek@apple.com>
Tue, 14 Jun 2011 22:56:51 +0000 (22:56 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 14 Jun 2011 22:56:51 +0000 (22:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133024 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/FormatString.cpp
lib/Analysis/PrintfFormatString.cpp
test/SemaObjC/format-strings-objc.m

index c1b5ea8a652a7c4849fb76358ae2d0a12d46e266..be214e0d86d488ef0e7c2aa3339374be584a9237 100644 (file)
@@ -300,7 +300,8 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const {
         argTy->isNullPtrType();
 
     case ObjCPointerTy:
-      return argTy->getAs<ObjCObjectPointerType>() != NULL;
+      return argTy->getAs<ObjCObjectPointerType>() != NULL ||
+             argTy->getAs<BlockPointerType>() != NULL;
   }
 
   // FIXME: Should be unreachable, but Clang is currently emitting
index 00b0b279e4a0f866904a7d27ad70dcacf052322f..270308a08f215fc5501061f9afb29a4a8a37a9e7 100644 (file)
@@ -348,6 +348,8 @@ ArgTypeResult PrintfSpecifier::getArgType(ASTContext &Ctx) const {
       return Ctx.WCharTy;
     case ConversionSpecifier::pArg:
       return ArgTypeResult::CPointerTy;
+    case ConversionSpecifier::ObjCObjArg:
+      return ArgTypeResult::ObjCPointerTy;
     default:
       break;
   }
index d89f50afa968a8bafa9ebe1dac9a120cb4cb3382..dd49cf7a936de4ed12e96f9933ceb46d54844ad7 100644 (file)
@@ -38,6 +38,7 @@ int printf(const char * restrict, ...) ;
 void check_nslog(unsigned k) {
   NSLog(@"%d%%", k); // no-warning
   NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{invalid conversion specifier 'b'}}
+  NSLog(@"%@", "a"); // expected-warning {{conversion specifies type 'id' but the argument has type 'char *'}}
 }
 
 // Check type validation