summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-21 00:27:41 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-21 00:27:41 +0000
commitb2ed28ea4b61f359354b2f62c44177f77b55bc9d (patch)
treed92ce2acee6a2910008e26c3eacf43df5cbdc4cd /clang/lib/CodeGen
parent21b2b7db76cff2f4d276a66050357c15e41e1e08 (diff)
downloadbcm5719-llvm-b2ed28ea4b61f359354b2f62c44177f77b55bc9d.tar.gz
bcm5719-llvm-b2ed28ea4b61f359354b2f62c44177f77b55bc9d.zip
For
double data[20000000] = {0}; we would blow out the memory by creating 20M Exprs to fill out the initializer. To fix this, if the initializer list initializes an array with more elements than there are initializers in the list, have InitListExpr store a single 'ArrayFiller' expression that specifies an expression to be used for value initialization of the rest of the elements. Fixes rdar://9275920. llvm-svn: 129896
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp2
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp10
2 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 6fb9987ecd7..5b3c0905e54 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -641,6 +641,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
if (i < NumInitElements)
EmitInitializationToLValue(E->getInit(i), LV, ElementType);
+ else if (Expr *filler = E->getArrayFiller())
+ EmitInitializationToLValue(filler, LV, ElementType);
else
EmitNullInitializationToLValue(LV, ElementType);
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 8e26b206ebf..338fb03b8a0 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -667,8 +667,16 @@ public:
// Initialize remaining array elements.
// FIXME: This doesn't handle member pointers correctly!
+ llvm::Constant *fillC;
+ if (Expr *filler = ILE->getArrayFiller())
+ fillC = CGM.EmitConstantExpr(filler, filler->getType(), CGF);
+ else
+ fillC = llvm::Constant::getNullValue(ElemTy);
+ if (!fillC)
+ return 0;
+ RewriteType |= (fillC->getType() != ElemTy);
for (; i < NumElements; ++i)
- Elts.push_back(llvm::Constant::getNullValue(ElemTy));
+ Elts.push_back(fillC);
if (RewriteType) {
// FIXME: Try to avoid packing the array
OpenPOWER on IntegriCloud