From a18829860c8b186d3a7f6a4ba83e21e9cbbffac1 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 9 Oct 2013 22:34:33 +0000 Subject: [PATCH] Refine string literal concatenation warning within an NSArray literal to not warn when the literal comes from a macro expansion. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192328 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 22 ++++++++++++++++++---- test/SemaObjC/objc-array-literal.m | 8 ++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 5550eb8cf9..7efa08b45c 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -410,10 +410,24 @@ static ExprResult CheckObjCCollectionLiteralElement(Sema &S, Expr *Element, } } if (ArrayLiteral) - if (ObjCStringLiteral *getString = dyn_cast(OrigElement)) { - if (getString->getString() && getString->getString()->getNumConcatenated() > 1) - S.Diag(Element->getLocStart(), diag::warn_concatenated_nsarray_literal) - << Element->getType(); + if (ObjCStringLiteral *getString = + dyn_cast(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 diff --git a/test/SemaObjC/objc-array-literal.m b/test/SemaObjC/objc-array-literal.m index e6e4c471b5..a3e29bf122 100644 --- a/test/SemaObjC/objc-array-literal.m +++ b/test/SemaObjC/objc-array-literal.m @@ -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; +} -- 2.40.0