diff options
Diffstat (limited to 'lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 5dba6846a3..6e40b3c4a3 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -20,9 +20,14 @@ using namespace clang; Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, ExprTy **Strings, unsigned NumStrings) { - SourceLocation AtLoc = AtLocs[0]; - StringLiteral* S = static_cast<StringLiteral *>(Strings[0]); - if (NumStrings > 1) { + // Most ObjC strings are formed out of a single piece. However, we *can* + // have strings formed out of multiple @ strings with multiple pptokens in + // each one, e.g. @"foo" "bar" @"baz" "qux" which need to be turned into one + // StringLiteral for ObjCStringLiteral to hold onto. + StringLiteral *S = static_cast<StringLiteral *>(Strings[0]); + + // If we have a multi-part string, merge it all together. + if (NumStrings != 1) { // Concatenate objc strings. StringLiteral* ES = static_cast<StringLiteral *>(Strings[NumStrings-1]); SourceLocation EndLoc = ES->getSourceRange().getEnd(); @@ -33,19 +38,22 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, // FIXME: This should not be allocated by SEMA! char *strBuf = new char[Length]; char *p = strBuf; - bool isWide = false; for (unsigned i = 0; i != NumStrings; ++i) { S = static_cast<StringLiteral *>(Strings[i]); - if (S->isWide()) - isWide = true; + if (S->isWide()) { + Diag(S->getLocStart(), diag::err_cfstring_literal_not_string_constant) + << S->getSourceRange(); + return true; + } + memcpy(p, S->getStrData(), S->getByteLength()); p += S->getByteLength(); S->Destroy(Context); } // FIXME: PASS LOCATIONS PROPERLY. - S = new (Context) StringLiteral(Context, strBuf, Length, isWide, + S = new (Context) StringLiteral(Context, strBuf, Length, false, Context.getPointerType(Context.CharTy), - AtLoc); + AtLocs[0]); } // Verify that this composite string is acceptable for ObjC strings. @@ -71,7 +79,7 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, } } - return new (Context) ObjCStringLiteral(S, Ty, AtLoc); + return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]); } Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc, |