summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprAgg.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-05-19 17:51:16 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-05-19 17:51:16 +0000
commit922696f03ec9637449e2cba260493808b4977cd3 (patch)
tree5428ff69752d31a3722d384d71e3d590cf341577 /lib/CodeGen/CGExprAgg.cpp
parentd72d16e6f105deb6fe890225a6251dd0e9001ce7 (diff)
downloadclang-922696f03ec9637449e2cba260493808b4977cd3.tar.gz
clang-922696f03ec9637449e2cba260493808b4977cd3.tar.bz2
clang-922696f03ec9637449e2cba260493808b4977cd3.tar.xz
Fix the emission of expressions like char a[10] = "asdf"; previously,
they were causing bad code to be emitted. There are two fixes here: one makes sure we emit a string that is long enough, and one makes sure we properly handle string initialization in init lists. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprAgg.cpp')
-rw-r--r--lib/CodeGen/CGExprAgg.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index 6b68705af7..c7c250ee7b 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -53,7 +53,7 @@ public:
void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
void EmitNonConstInit(InitListExpr *E);
-
+
//===--------------------------------------------------------------------===//
// Visitor Methods
//===--------------------------------------------------------------------===//
@@ -336,7 +336,6 @@ void AggExprEmitter::EmitNullInitializationToLValue(LValue LV, QualType T) {
}
}
-
void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
if (E->isConstantExpr(CGF.getContext(), 0)) {
// FIXME: call into const expr emitter so that we can emit
@@ -355,6 +354,14 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
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();