summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-06-07 18:15:55 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-06-07 18:15:55 +0000
commit5d53fcda7c4cf189b094caf1ed3270d416a9610f (patch)
tree43b7b3de6408a638f731a125389b75abcc8c800f
parentfed6699dd9d7b27bbbc52644cc14a855b09913c4 (diff)
downloadbcm5719-llvm-5d53fcda7c4cf189b094caf1ed3270d416a9610f.tar.gz
bcm5719-llvm-5d53fcda7c4cf189b094caf1ed3270d416a9610f.zip
User better API for vla in compund literals.
// rdar://11485774 llvm-svn: 158157
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp7
-rw-r--r--clang/test/CodeGen/vla.c39
2 files changed, 37 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5d1890635e0..198a9bcd6fe 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2114,10 +2114,9 @@ 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());
+ if (E->getType()->isVariablyModifiedType())
+ // make sure to emit the VLA size.
+ EmitVariablyModifiedType(E->getType());
llvm::Value *DeclPtr = CreateMemTemp(E->getType(), ".compoundliteral");
const Expr *InitExpr = E->getInitializer();
diff --git a/clang/test/CodeGen/vla.c b/clang/test/CodeGen/vla.c
index 147f2d4fa81..e1518276270 100644
--- a/clang/test/CodeGen/vla.c
+++ b/clang/test/CodeGen/vla.c
@@ -155,10 +155,39 @@ void test5(void)
(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: [[INC:%.*]] = add nsw i32 [[Z]], 1
+ // CHECK-NEXT: store i32 [[INC]], i32* [[I]], align 4
+ // CHECK-NEXT: [[O:%.*]] = load i32* [[I]], align 4
+ // CHECK-NEXT: [[AR:%.*]] = getelementptr inbounds [5 x i32]* [[A]], i32 0, i32 0
+ // CHECK-NEXT: [[T:%.*]] = bitcast [5 x i32]* [[A]] to i32*
+ // CHECK-NEXT: store i32* [[T]], i32** [[CL]]
+ // CHECK-NEXT: [[TH:%.*]] = load i32** [[CL]]
+ // CHECK-NEXT: [[VLAIX:%.*]] = mul nsw i32 0, [[O]]
+ // CHECK-NEXT: [[ADDPTR:%.*]] = getelementptr inbounds i32* [[TH]], i32 [[VLAIX]]
// CHECK-NEXT: store i32* [[ADDPTR]], i32** [[CL]]
}
+
+void test6(void)
+{
+ // CHECK: define void @test6(
+ int n = 20, **a, i=0;
+ // CHECK: [[N:%.*]] = alloca i32, align 4
+ // CHECK-NEXT: [[A:%.*]] = alloca i32**, align 4
+ // CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
+ (int (**)[i]){&a}[0][1][5] = 0;
+ // CHECK-NEXT: [[CL:%.*]] = alloca i32**, align 4
+ // CHECK-NEXT: store i32 20, i32* [[N]], align 4
+ // CHECK-NEXT: store i32 0, i32* [[I]], align 4
+ // CHECK-NEXT: [[Z:%.*]] = load i32* [[I]], align 4
+ // CHECK-NEXT: [[O:%.*]] = bitcast i32*** [[A]] to i32**
+ // CHECK-NEXT: store i32** [[O]], i32*** [[CL]]
+ // CHECK-NEXT: [[T:%.*]] = load i32*** [[CL]]
+ // CHECK-NEXT: [[IX:%.*]] = getelementptr inbounds i32** [[T]], i32 0
+ // CHECK-NEXT: [[TH:%.*]] = load i32** [[IX]], align 4
+ // CHECK-NEXT: [[F:%.*]] = mul nsw i32 1, [[Z]]
+ // CHECK-NEXT: [[IX1:%.*]] = getelementptr inbounds i32* [[TH]], i32 [[F]]
+ // CHECK-NEXT: [[IX2:%.*]] = getelementptr inbounds i32* [[IX1]], i32 5
+ // CHECK-NEXT: store i32 0, i32* [[IX2]], align 4
+}
+
+
OpenPOWER on IntegriCloud