LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) {
assert(!E->isWide() && "FIXME: Wide strings not supported yet!");
+ // Get the string data
const char *StrData = E->getStrData();
unsigned Len = E->getByteLength();
std::string StringLiteral(StrData, StrData+Len);
+
+ // Resize the string to the right size
+ const ConstantArrayType *CAT = E->getType()->getAsConstantArrayType();
+ uint64_t RealLen = CAT->getSize().getZExtValue();
+ StringLiteral.resize(RealLen, '\0');
+
return LValue::MakeAddr(CGM.GetAddrOfConstantString(StringLiteral));
}
void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
void EmitNonConstInit(InitListExpr *E);
-
+
//===--------------------------------------------------------------------===//
// Visitor Methods
//===--------------------------------------------------------------------===//
}
}
-
void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
if (E->isConstantExpr(CGF.getContext(), 0)) {
// FIXME: call into const expr emitter so that we can emit
cast<llvm::ArrayType>(APType->getElementType());
uint64_t NumInitElements = E->getNumInits();
+
+ if (E->getNumInits() > 0 &&
+ E->getType().getCanonicalType().getUnqualifiedType() ==
+ E->getInit(0)->getType().getCanonicalType().getUnqualifiedType()) {
+ EmitAggLoadOfLValue(E->getInit(0));
+ return;
+ }
+
uint64_t NumArrayElements = AType->getNumElements();
QualType ElementType = E->getType()->getAsArrayType()->getElementType();
--- /dev/null
+// RUN: clang -emit-llvm %s -o - | not grep "[5 x i8]"
+// RUN: clang -emit-llvm %s -o - | not grep "store"
+
+void test(void) {
+ char a[10] = "asdf";
+ char b[10] = { "asdf" };
+}
+