[cfe-commits] r148885 - in /cfe/trunk: lib/Analysis/FormatString.cpp lib/Analysis/PrintfFormatString.cpp test/SemaObjC/format-strings-objc.m

Ted Kremenek kremenek at apple.com
Tue Jan 24 16:04:09 PST 2012


Author: kremenek
Date: Tue Jan 24 18:04:09 2012
New Revision: 148885

URL: http://llvm.org/viewvc/llvm-project?rev=148885&view=rev
Log:
Fix NSLog format string checking for %@.

Modified:
    cfe/trunk/lib/Analysis/FormatString.cpp
    cfe/trunk/lib/Analysis/PrintfFormatString.cpp
    cfe/trunk/test/SemaObjC/format-strings-objc.m

Modified: cfe/trunk/lib/Analysis/FormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=148885&r1=148884&r2=148885&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/FormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/FormatString.cpp Tue Jan 24 18:04:09 2012
@@ -337,7 +337,8 @@
         argTy->isNullPtrType();
 
     case ObjCPointerTy:
-      return argTy->getAs<ObjCObjectPointerType>() != NULL;
+      return argTy->getAs<ObjCObjectPointerType>() ||
+             argTy->getAs<BlockPointerType>();
   }
 
   llvm_unreachable("Invalid ArgTypeResult Kind!");

Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=148885&r1=148884&r2=148885&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Tue Jan 24 18:04:09 2012
@@ -319,6 +319,8 @@
       return ArgTypeResult(Ctx.WCharTy, "wchar_t");
     case ConversionSpecifier::pArg:
       return ArgTypeResult::CPointerTy;
+    case ConversionSpecifier::ObjCObjArg:
+      return ArgTypeResult::ObjCPointerTy;
     default:
       break;
   }

Modified: cfe/trunk/test/SemaObjC/format-strings-objc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/format-strings-objc.m?rev=148885&r1=148884&r2=148885&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/format-strings-objc.m (original)
+++ cfe/trunk/test/SemaObjC/format-strings-objc.m Tue Jan 24 18:04:09 2012
@@ -13,6 +13,7 @@
 typedef unsigned int NSUInteger;
 @class NSString, Protocol;
 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
+extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
 typedef struct _NSZone NSZone;
 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
 @protocol NSObject  - (BOOL)isEqual:(id)object; @end
@@ -82,3 +83,9 @@
   [Foo fooWithFormat:@"%@"]; // expected-warning {{more '%' conversions than data arguments}}
   [Foo fooWithCStringFormat:"%@"]; // expected-warning {{invalid conversion specifier '@'}}
 }
+
+// Warn about using BOOL with %@
+void rdar10743758(id x) {
+  NSLog(@"%@ %@", x, (BOOL) 1); // expected-warning {{format specifies type 'id' but the argument has type 'BOOL' (aka 'signed char')}}
+}
+





More information about the cfe-commits mailing list