[cfe-commits] r158157 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/vla.c
Fariborz Jahanian
fjahanian at apple.com
Thu Jun 7 11:15:55 PDT 2012
Author: fjahanian
Date: Thu Jun 7 13:15:55 2012
New Revision: 158157
URL: http://llvm.org/viewvc/llvm-project?rev=158157&view=rev
Log:
User better API for vla in compund literals.
// rdar://11485774
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/vla.c
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=158157&r1=158156&r2=158157&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun 7 13:15:55 2012
@@ -2114,10 +2114,9 @@
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();
Modified: cfe/trunk/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vla.c?rev=158157&r1=158156&r2=158157&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/vla.c (original)
+++ cfe/trunk/test/CodeGen/vla.c Thu Jun 7 13:15:55 2012
@@ -155,10 +155,39 @@
(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
+}
+
+
More information about the cfe-commits
mailing list