r192328 - Refine string literal concatenation warning within an NSArray literal to not warn when the literal comes from a macro expansion. Fixes <rdar://problem/15147688>.
Ted Kremenek
kremenek at apple.com
Wed Oct 9 15:34:33 PDT 2013
Author: kremenek
Date: Wed Oct 9 17:34:33 2013
New Revision: 192328
URL: http://llvm.org/viewvc/llvm-project?rev=192328&view=rev
Log:
Refine string literal concatenation warning within an NSArray literal to not warn when the literal comes from a macro expansion. Fixes <rdar://problem/15147688>.
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/objc-array-literal.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=192328&r1=192327&r2=192328&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Oct 9 17:34:33 2013
@@ -410,10 +410,24 @@ static ExprResult CheckObjCCollectionLit
}
}
if (ArrayLiteral)
- if (ObjCStringLiteral *getString = dyn_cast<ObjCStringLiteral>(OrigElement)) {
- if (getString->getString() && getString->getString()->getNumConcatenated() > 1)
- S.Diag(Element->getLocStart(), diag::warn_concatenated_nsarray_literal)
- << Element->getType();
+ if (ObjCStringLiteral *getString =
+ dyn_cast<ObjCStringLiteral>(OrigElement)) {
+ if (StringLiteral *SL = getString->getString()) {
+ unsigned numConcat = SL->getNumConcatenated();
+ if (numConcat > 1) {
+ // Only warn if the concatenated string doesn't come from a macro.
+ bool hasMacro = false;
+ for (unsigned i = 0; i < numConcat ; ++i)
+ if (SL->getStrTokenLoc(i).isMacroID()) {
+ hasMacro = true;
+ break;
+ }
+ if (!hasMacro)
+ S.Diag(Element->getLocStart(),
+ diag::warn_concatenated_nsarray_literal)
+ << Element->getType();
+ }
+ }
}
// Make sure that the element has the type that the container factory
Modified: cfe/trunk/test/SemaObjC/objc-array-literal.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-array-literal.m?rev=192328&r1=192327&r2=192328&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-array-literal.m (original)
+++ cfe/trunk/test/SemaObjC/objc-array-literal.m Wed Oct 9 17:34:33 2013
@@ -45,3 +45,11 @@ id Test14303083() {
id obj = @[ @"A", (@"B" @"C")];
return @[ @"A", @"B" @"C"]; // expected-warning {{concatenated NSString literal for an NSArray expression - possibly missing a comma}}
}
+id radar15147688() {
+#define R15147688_A @"hello"
+#define R15147688_B "world"
+#define CONCATSTR R15147688_A R15147688_B
+ id x = @[ @"stuff", CONCATSTR ]; // no-warning
+ x = @[ @"stuff", @"hello" "world"]; // expected-warning {{concatenated NSString literal for an NSArray expression}}
+ return x;
+}
More information about the cfe-commits
mailing list