[llvm-branch-commits] [cfe-branch] r118576 - in /cfe/branches/Apple/whitney: lib/CodeGen/CGExpr.cpp test/CodeGen/vla.c
Daniel Dunbar
daniel at zuster.org
Tue Nov 9 09:32:45 PST 2010
Author: ddunbar
Date: Tue Nov 9 11:32:44 2010
New Revision: 118576
URL: http://llvm.org/viewvc/llvm-project?rev=118576&view=rev
Log:
Merge r118468:
--
Author: Argyrios Kyrtzidis <akyrtzi at gmail.com>
Date: Tue Nov 9 01:30:48 2010 +0000
Fix miscompilation regarding VLAs; subscription of VLA pointers was incorrect.
Fixes rdar://8644873 & http://llvm.org/PR8567.
Modified:
cfe/branches/Apple/whitney/lib/CodeGen/CGExpr.cpp
cfe/branches/Apple/whitney/test/CodeGen/vla.c
Modified: cfe/branches/Apple/whitney/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/CodeGen/CGExpr.cpp?rev=118576&r1=118575&r2=118576&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/branches/Apple/whitney/lib/CodeGen/CGExpr.cpp Tue Nov 9 11:32:44 2010
@@ -1433,17 +1433,14 @@
Idx = Builder.CreateMul(Idx, VLASize);
- QualType BaseType = getContext().getBaseElementType(VAT);
+ const llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(VMContext);
- CharUnits BaseTypeSize = getContext().getTypeSizeInChars(BaseType);
- Idx = Builder.CreateUDiv(Idx,
- llvm::ConstantInt::get(Idx->getType(),
- BaseTypeSize.getQuantity()));
-
// The base must be a pointer, which is not an aggregate. Emit it.
llvm::Value *Base = EmitScalarExpr(E->getBase());
- Address = Builder.CreateInBoundsGEP(Base, Idx, "arrayidx");
+ Address = Builder.CreateInBoundsGEP(Builder.CreateBitCast(Base, i8PTy),
+ Idx, "arrayidx");
+ Address = Builder.CreateBitCast(Address, Base->getType());
} else if (const ObjCObjectType *OIT = E->getType()->getAs<ObjCObjectType>()){
// Indexing over an interface, as in "NSString *P; P[4];"
llvm::Value *InterfaceSize =
Modified: cfe/branches/Apple/whitney/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/CodeGen/vla.c?rev=118576&r1=118575&r2=118576&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/CodeGen/vla.c (original)
+++ cfe/branches/Apple/whitney/test/CodeGen/vla.c Tue Nov 9 11:32:44 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
int b(char* x);
@@ -85,3 +85,16 @@
return GLOB;
}
+// http://llvm.org/PR8567
+// CHECK: define double @test_PR8567
+double test_PR8567(int n, double (*p)[n][5]) {
+ // CHECK: store [[vla_type:.*]] %p,
+ // CHECK: load i32* %n
+ // CHECK-NEXT: mul i32 40
+ // CHECK-NEXT: [[byte_idx:%.*]] = mul i32 1
+ // CHECK-NEXT: [[tmp_1:%.*]] = load [[vla_type]]*
+ // CHECK-NEXT: [[tmp_2:%.*]] = bitcast [[vla_type]] [[tmp_1]] to i8*
+ // CHECK-NEXT: [[idx:%.*]] = getelementptr inbounds i8* [[tmp_2]], i32 [[byte_idx]]
+ // CHECK-NEXT: bitcast i8* [[idx]] to [[vla_type]]
+ return p[1][2][3];
+}
More information about the llvm-branch-commits
mailing list