aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CGExpr.cpp6
-rw-r--r--test/CodeGen/vla.c20
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 190855d3a0..5d1890635e 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -2114,7 +2114,11 @@ LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr *E){
llvm::Value *GlobalPtr = CGM.GetAddrOfConstantCompoundLiteral(E);
return MakeAddrLValue(GlobalPtr, E->getType());
}
-
+ if (const PointerType *pointerType = E->getType()->getAs<PointerType>())
+ if (pointerType->getPointeeType()->isVariableArrayType())
+ // make sure to emit the VLA size.
+ EmitVariablyModifiedType(pointerType->getPointeeType());
+
llvm::Value *DeclPtr = CreateMemTemp(E->getType(), ".compoundliteral");
const Expr *InitExpr = E->getInitializer();
LValue Result = MakeAddrLValue(DeclPtr, E->getType());
diff --git a/test/CodeGen/vla.c b/test/CodeGen/vla.c
index 9e62da52e0..147f2d4fa8 100644
--- a/test/CodeGen/vla.c
+++ b/test/CodeGen/vla.c
@@ -142,3 +142,23 @@ int test4(unsigned n, char (*p)[n][n+1][6]) {
// CHECK-NEXT: ret i32 [[T7]]
return p2 - p;
}
+
+// rdar://11485774
+void test5(void)
+{
+ // CHECK: define void @test5(
+ int a[5], i = 0;
+ // CHECK: [[A:%.*]] = alloca [5 x i32], align 4
+ // CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
+ // CHECK-NEXT: [[CL:%.*]] = alloca i32*, align 4
+ // CHECK-NEXT: store i32 0, i32* [[I]], align 4
+
+ (typeof(++i, (int (*)[i])a)){&a} += 0;
+ // CHECK-NEXT: [[Z:%.*]] = load i32* [[I]], align 4
+ // CHECK-NEXT: [[O:%.*]] = bitcast [5 x i32]* [[A]] to i32*
+ // CHECK-NEXT: store i32* [[O]], i32** [[CL]]
+ // CHECK-NEXT: [[T:%.*]] = load i32** [[CL]]
+ // CHECK-NEXT: [[VLAIX:%.*]] = mul nsw i32 0, [[Z]]
+ // CHECK-NEXT: [[ADDPTR:%.*]] = getelementptr inbounds i32* [[T]], i32 [[VLAIX]]
+ // CHECK-NEXT: store i32* [[ADDPTR]], i32** [[CL]]
+}