[cfe-commits] r148948 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaObjC/format-strings-objc.m

Jean-Daniel Dupas devlists at shadowlab.org
Wed Jan 25 02:35:34 PST 2012


Author: jddupas
Date: Wed Jan 25 04:35:33 2012
New Revision: 148948

URL: http://llvm.org/viewvc/llvm-project?rev=148948&view=rev
Log:
Add support for const pointer to literal-objc string as format attribute.


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaObjC/format-strings-objc.m

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=148948&r1=148947&r2=148948&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Jan 25 04:35:33 2012
@@ -1441,6 +1441,10 @@
       } else if (const PointerType *PT = T->getAs<PointerType>()) {
         isConstant = T.isConstant(Context) &&
                      PT->getPointeeType().isConstant(Context);
+      } else if (T->isObjCObjectPointerType()) {
+        // In ObjC, there is usually no "const ObjectPointer" type,
+        // so don't check if the pointee type is constant.
+        isConstant = T.isConstant(Context);
       }
 
       if (isConstant) {

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=148948&r1=148947&r2=148948&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/format-strings-objc.m (original)
+++ cfe/trunk/test/SemaObjC/format-strings-objc.m Wed Jan 25 04:35:33 2012
@@ -89,3 +89,21 @@
   NSLog(@"%@ %@", x, (BOOL) 1); // expected-warning {{format specifies type 'id' but the argument has type 'BOOL' (aka 'signed char')}}
 }
 
+NSString *test_literal_propagation(void) {
+  const char * const s1 = "constant string %s"; // expected-note {{format string is defined here}}
+  printf(s1); // expected-warning {{more '%' conversions than data arguments}}
+  const char * const s5 = "constant string %s"; // expected-note {{format string is defined here}}
+  const char * const s2 = s5;
+  printf(s2); // expected-warning {{more '%' conversions than data arguments}}
+
+  const char * const s3 = (const char *)0;
+  printf(s3); // expected-warning {{format string is not a string literal}}
+
+  NSString * const ns1 = @"constant string %s"; // expected-note {{format string is defined here}}
+  NSLog(ns1); // expected-warning {{more '%' conversions than data arguments}}
+  NSString * const ns5 = @"constant string %s"; // expected-note {{format string is defined here}}
+  NSString * const ns2 = ns5;
+  NSLog(ns2); // expected-warning {{more '%' conversions than data arguments}}
+  NSString * ns3 = ns1;
+  NSLog(ns3); // expected-warning {{format string is not a string literal}}}
+}





More information about the cfe-commits mailing list