diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-09 01:30:48 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-09 01:30:48 +0000 |
| commit | 8909686b2282231201c354bffe92bda833f12ab0 (patch) | |
| tree | 3b81398aecbacbf0f609216e0431c1395bda2773 /clang/lib/CodeGen | |
| parent | 45b49245502eda6ab774b3d6ecd9398d86d17717 (diff) | |
| download | bcm5719-llvm-8909686b2282231201c354bffe92bda833f12ab0.tar.gz bcm5719-llvm-8909686b2282231201c354bffe92bda833f12ab0.zip | |
Fix miscompilation regarding VLAs; subscription of VLA pointers was incorrect.
Fixes rdar://8644873 & http://llvm.org/PR8567.
llvm-svn: 118468
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 1d86036c797..355c18f79c5 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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 = |

