change the StringLiteral AST node to track all of the SourceLocations of
the various PPTokens that are pasted together to make it. In the course
of working on this, I discovered ParseObjCStringLiteral which needs some
work. I'll tackle it next.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64892 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 4eb29c4..c0b61bf 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -352,13 +352,17 @@
StrTy = Context.getConstantArrayType(StrTy,
llvm::APInt(32, Literal.GetStringLength()+1),
ArrayType::Normal, 0);
-
+ // Allocate enough space for the StringLiteral plus an array of locations for
+ // any concatenated strings.
+ void *Mem = Context.Allocate(sizeof(StringLiteral)+
+ sizeof(SourceLocation)*(NumStringToks-1));
+
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
- return Owned(new (Context) StringLiteral(Context, Literal.GetString(),
- Literal.GetStringLength(),
- Literal.AnyWide, StrTy,
- StringToks[0].getLocation(),
- StringToks[NumStringToks-1].getLocation()));
+ return Owned(new (Mem) StringLiteral(Context, Literal.GetString(),
+ Literal.GetStringLength(),
+ Literal.AnyWide, StrTy,
+ &StringTokLocs[0],
+ StringTokLocs.size()));
}
/// ShouldSnapshotBlockValueReference - Return true if a reference inside of
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 3e99482..b0b5367 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -29,10 +29,12 @@
unsigned Length = 0;
for (unsigned i = 0; i < NumStrings; i++)
Length += static_cast<StringLiteral *>(Strings[i])->getByteLength();
- char *strBuf = new char [Length];
+
+ // 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++) {
+ for (unsigned i = 0; i != NumStrings; ++i) {
S = static_cast<StringLiteral *>(Strings[i]);
if (S->isWide())
isWide = true;
@@ -40,9 +42,10 @@
p += S->getByteLength();
S->Destroy(Context);
}
- S = new (Context, 8) StringLiteral(Context, strBuf, Length, isWide,
- Context.getPointerType(Context.CharTy),
- AtLoc, EndLoc);
+ // FIXME: PASS LOCATIONS PROPERLY.
+ S = new (Context) StringLiteral(Context, strBuf, Length, isWide,
+ Context.getPointerType(Context.CharTy),
+ AtLoc);
}
if (CheckBuiltinCFStringArgument(S))