diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-01-25 10:35:33 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-01-25 10:35:33 +0000 |
commit | d5f7ef48e232b18eb7b25e0ddf8151ba409f9d25 (patch) | |
tree | 58fee43072134e2efdb479028c019d1ae07d4348 | |
parent | 33633a90a029ee4eb840f524753f5935a3103cfa (diff) | |
download | bcm5719-llvm-d5f7ef48e232b18eb7b25e0ddf8151ba409f9d25.tar.gz bcm5719-llvm-d5f7ef48e232b18eb7b25e0ddf8151ba409f9d25.zip |
Add support for const pointer to literal-objc string as format attribute.
llvm-svn: 148948
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 4 | ||||
-rw-r--r-- | clang/test/SemaObjC/format-strings-objc.m | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index f5a8b448a17..950a5758918 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1441,6 +1441,10 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args, } 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) { diff --git a/clang/test/SemaObjC/format-strings-objc.m b/clang/test/SemaObjC/format-strings-objc.m index a2fe841ced2..b0c87fe243d 100644 --- a/clang/test/SemaObjC/format-strings-objc.m +++ b/clang/test/SemaObjC/format-strings-objc.m @@ -89,3 +89,21 @@ void rdar10743758(id x) { 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}}} +} |