[cfe-commits] r158153 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/vla.c

Fariborz Jahanian fjahanian at apple.com
Thu Jun 7 10:07:15 PDT 2012


Author: fjahanian
Date: Thu Jun  7 12:07:15 2012
New Revision: 158153

URL: http://llvm.org/viewvc/llvm-project?rev=158153&view=rev
Log:
When emitting compund literal of vla pointer elements, make 
sure to emit vla size to prevent an irgen crash.
// 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=158153&r1=158152&r2=158153&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun  7 12:07:15 2012
@@ -2114,7 +2114,11 @@
     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());

Modified: cfe/trunk/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vla.c?rev=158153&r1=158152&r2=158153&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/vla.c (original)
+++ cfe/trunk/test/CodeGen/vla.c Thu Jun  7 12:07:15 2012
@@ -142,3 +142,23 @@
   // 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]]
+}





More information about the cfe-commits mailing list