summaryrefslogtreecommitdiff
path: root/lib/Serialization/ASTReaderStmt.cpp
diff options
context:
space:
mode:
authorBruno Ricci <riccibrun@gmail.com>2018-11-15 17:31:16 +0000
committerBruno Ricci <riccibrun@gmail.com>2018-11-15 17:31:16 +0000
commit2b074a4200135c633ba23aadb1d86b8b60b9c871 (patch)
tree50c38439f76e9a418b6f7a5609bc940a309e73e9 /lib/Serialization/ASTReaderStmt.cpp
parentb9e6abd1ea926a4d0b2395a4e6e1a1f2f4fe1f7b (diff)
downloadclang-2b074a4200135c633ba23aadb1d86b8b60b9c871.tar.gz
[AST] Store the string data in StringLiteral in a trailing array of chars
Use the newly available space in the bit-fields of Stmt and store the string data in a trailing array of chars after the trailing array of SourceLocation. This cuts the size of StringLiteral by 2 pointers. Also refactor slightly StringLiteral::Create and StringLiteral::CreateEmpty so that StringLiteral::Create is just responsible for the allocation, and the constructor is responsible for doing all the initialization. This match what is done for the other classes in general. This patch should have no other functional changes apart from this. A concern was raised during review about the interaction between this patch and serialization abbreviations. I believe however that there is currently no abbreviation defined for StringLiteral. The only statements/expressions which have abbreviations are currently DeclRefExpr, IntegerLiteral, CharacterLiteral and ImplicitCastExpr. Differential Revision: https://reviews.llvm.org/D54166 Reviewed By: dblaikie, rjmccall git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTReaderStmt.cpp')
-rw-r--r--lib/Serialization/ASTReaderStmt.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp
index ef370260c5..15e89db209 100644
--- a/lib/Serialization/ASTReaderStmt.cpp
+++ b/lib/Serialization/ASTReaderStmt.cpp
@@ -595,22 +595,35 @@ void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
VisitExpr(E);
- unsigned Len = Record.readInt();
- assert(Record.peekInt() == E->getNumConcatenated() &&
- "Wrong number of concatenated tokens!");
- Record.skipInts(1);
- auto kind = static_cast<StringLiteral::StringKind>(Record.readInt());
- bool isPascal = Record.readInt();
- // Read string data
- auto B = &Record.peekInt();
- SmallString<16> Str(B, B + Len);
- E->setString(Record.getContext(), Str, kind, isPascal);
- Record.skipInts(Len);
-
- // Read source locations
- for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
+ // NumConcatenated, Length and CharByteWidth are set by the empty
+ // ctor since they are needed to allocate storage for the trailing objects.
+ unsigned NumConcatenated = Record.readInt();
+ unsigned Length = Record.readInt();
+ unsigned CharByteWidth = Record.readInt();
+ assert((NumConcatenated == E->getNumConcatenated()) &&
+ "Wrong number of concatenated tokens!");
+ assert((Length == E->getLength()) && "Wrong Length!");
+ assert((CharByteWidth == E->getCharByteWidth()) && "Wrong character width!");
+ E->StringLiteralBits.Kind = Record.readInt();
+ E->StringLiteralBits.IsPascal = Record.readInt();
+
+ // The character width is originally computed via mapCharByteWidth.
+ // Check that the deserialized character width is consistant with the result
+ // of calling mapCharByteWidth.
+ assert((CharByteWidth ==
+ StringLiteral::mapCharByteWidth(Record.getContext().getTargetInfo(),
+ E->getKind())) &&
+ "Wrong character width!");
+
+ // Deserialize the trailing array of SourceLocation.
+ for (unsigned I = 0; I < NumConcatenated; ++I)
E->setStrTokenLoc(I, ReadSourceLocation());
+
+ // Deserialize the trailing array of char holding the string data.
+ char *StrData = E->getStrDataAsChar();
+ for (unsigned I = 0; I < Length * CharByteWidth; ++I)
+ StrData[I] = Record.readInt();
}
void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
@@ -2423,8 +2436,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
break;
case EXPR_STRING_LITERAL:
- S = StringLiteral::CreateEmpty(Context,
- Record[ASTStmtReader::NumExprFields + 1]);
+ S = StringLiteral::CreateEmpty(
+ Context,
+ /* NumConcatenated=*/Record[ASTStmtReader::NumExprFields + 0],
+ /* Length=*/Record[ASTStmtReader::NumExprFields + 1],
+ /* CharByteWidth=*/Record[ASTStmtReader::NumExprFields + 2]);
break;
case EXPR_CHARACTER_LITERAL: