aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-08-10 20:25:57 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-08-10 20:25:57 +0000
commit1e04976fc2611d8cc06986a81deed4c42183b870 (patch)
tree1c6d0b660c3141ec9bf4ba557f8080f8656e8537 /lib/CodeGen/CGExprConstant.cpp
parent7bfaaaecb3113f955db31e8d8a51acffd1bc0c27 (diff)
Back out r54608 (inline string literals were getting an extra '\0')
temporarily, I assumed GetAddrForConstantString literal was being used consistently but it doesn't look like it is. Factored out a CodeGenModule::getStringForStringLiteral which handles extracting a std::string for the bytes of a StringLiteral, padded to match the type. Update EmitLValue to use getStringForStringLiteral, this was previously not padding strings correctly. Good thing we only emit strings in 4 different places! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54621 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp26
1 files changed, 3 insertions, 23 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 095153229e..db8003e43e 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -354,28 +354,12 @@ public:
}
llvm::Constant *VisitStringLiteral(StringLiteral *E) {
- const char *StrData = E->getStrData();
- unsigned Len = E->getByteLength();
assert(!E->getType()->isPointerType() && "Strings are always arrays");
// Otherwise this must be a string initializing an array in a static
// initializer. Don't emit it as the address of the string, emit the string
// data itself as an inline array.
- const ConstantArrayType *CAT =
- CGM.getContext().getAsConstantArrayType(E->getType());
- assert(CAT && "String isn't pointer or array!");
-
- std::string Str(StrData, StrData + Len);
- // Null terminate the string before potentially truncating it.
- // FIXME: What about wchar_t strings?
- Str.push_back(0);
-
- uint64_t RealLen = CAT->getSize().getZExtValue();
- // String or grow the initializer to the required size.
- if (RealLen != Str.size())
- Str.resize(RealLen);
-
- return llvm::ConstantArray::get(Str, false);
+ return llvm::ConstantArray::get(CGM.getStringForStringLiteral(E), false);
}
llvm::Constant *VisitDeclRefExpr(DeclRefExpr *E) {
@@ -775,12 +759,8 @@ public:
return llvm::ConstantExpr::getGetElementPtr(Base, &Index, 1);
}
case Expr::StringLiteralClass: {
- StringLiteral *String = cast<StringLiteral>(E);
- assert(!String->isWide() && "Cannot codegen wide strings yet");
- const char *StrData = String->getStrData();
- unsigned Len = String->getByteLength();
-
- return CGM.GetAddrOfConstantString(std::string(StrData, StrData + Len));
+ StringLiteral *S = cast<StringLiteral>(E);
+ return CGM.GetAddrOfConstantString(CGM.getStringForStringLiteral(S));
}
case Expr::UnaryOperatorClass: {
UnaryOperator *Exp = cast<UnaryOperator>(E);