From 981b6fde6992567d8be03ba77dabe1efc3ff33d1 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 9 Nov 2010 01:30:48 +0000 Subject: 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 --- lib/CodeGen/CGExpr.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/CGExpr.cpp') 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()){ // Indexing over an interface, as in "NSString *P; P[4];" llvm::Value *InterfaceSize = -- cgit v1.2.3