aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-06-07 17:07:15 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-06-07 17:07:15 +0000
commit2ccc0f9c23e6b948a4db6ffe46aefa098e1a2956 (patch)
tree07bf3ba5b2deea43d7d36fc84e1d6ba0932dc760
parentb8e54cd26cc71075456a74be054a95fa1f2e28ad (diff)
When emitting compund literal of vla pointer elements, make
sure to emit vla size to prevent an irgen crash. // rdar://11485774 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158153 91177308-0d34-0410-b5e6-96231b3b80d8
-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]]
+}