summaryrefslogtreecommitdiffstats
path: root/clang/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
commit6dfdf8c97a79b14ecca3aba0bc1aff612cd62226 (patch)
tree77a7f034595384b4c5d93cb367c245fa669223f4 /clang/lib/CodeGen/CGExprConstant.cpp
parent4c3116437cc19d05b3031b8e99566ef47bf463e8 (diff)
downloadbcm5719-llvm-6dfdf8c97a79b14ecca3aba0bc1aff612cd62226.tar.gz
bcm5719-llvm-6dfdf8c97a79b14ecca3aba0bc1aff612cd62226.zip
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! llvm-svn: 54621
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp26
1 files changed, 3 insertions, 23 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 095153229e6..db8003e43e0 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud