[cfe-commits] r158117 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/vla.c
Fariborz Jahanian
fjahanian at apple.com
Wed Jun 6 15:58:50 PDT 2012
Author: fjahanian
Date: Wed Jun 6 17:58:50 2012
New Revision: 158117
URL: http://llvm.org/viewvc/llvm-project?rev=158117&view=rev
Log:
When doing arithmatic on vla pointer, make sure
to emit vla size to prevent an irgen crash.
// rdar://11485774
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/vla.c
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=158117&r1=158116&r2=158117&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Jun 6 17:58:50 2012
@@ -1970,6 +1970,9 @@
QualType elementType = pointerType->getPointeeType();
if (const VariableArrayType *vla
= CGF.getContext().getAsVariableArrayType(elementType)) {
+ // arithmatic on VLA pointer - make sure to emit the VLA size.
+ CGF.EmitVariablyModifiedType(elementType);
+
// The element count here is the total number of non-VLA elements.
llvm::Value *numElements = CGF.getVLASize(vla).first;
Modified: cfe/trunk/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vla.c?rev=158117&r1=158116&r2=158117&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/vla.c (original)
+++ cfe/trunk/test/CodeGen/vla.c Wed Jun 6 17:58:50 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:%.*]] = bitcast [5 x i32]* [[A]] to i32*
+ // CHECK-NEXT: store i32* [[Z]], i32** [[CL]]
+ // CHECK-NEXT: [[O:%.*]] = load i32** [[CL]]
+ // CHECK-NEXT: [[T:%.*]] = load i32* [[I]], align 4
+ // CHECK-NEXT: [[VLAIX:%.*]] = mul nsw i32 0, [[T]]
+ // CHECK-NEXT: [[ADDPTR:%.*]] = getelementptr inbounds i32* [[O]], i32 [[VLAIX]]
+ // CHECK-NEXT: store i32* [[ADDPTR]], i32** [[CL]]
+}
More information about the cfe-commits
mailing list