aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-11-09 01:30:48 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-11-09 01:30:48 +0000
commit981b6fde6992567d8be03ba77dabe1efc3ff33d1 (patch)
treefeb338fb4c317e6966e4f409ecbda1c0faa90f85 /lib/CodeGen/CGExpr.cpp
parent4e3b17c9ce4a198eaeac4355b12e4b523185ecb5 (diff)
Fix miscompilation regarding VLAs; subscription of VLA pointers was incorrect.
Fixes rdar://8644873 & http://llvm.org/PR8567. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118468 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 1d86036c79..355c18f79c 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1433,17 +1433,14 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
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 =