diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-04-25 05:08:32 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-04-25 05:08:32 +0000 |
commit | 2a866251a80a8d88f6908f7dc68ce06d1023ec1d (patch) | |
tree | b8ef33515f4eacacc28fc17765c1c031dd71c7c9 /lib/CodeGen/CGExpr.cpp | |
parent | 4da0427a20f31db9b6934b280d49ab264236b34c (diff) |
Fix pointer addressing and array subscripting of Objective-C interface
types.
- I broke this in the switch to representing interfaces with opaque
types.
- <rdar://problem/6822660> clang crashes on subscript of interface in
32-bit mode
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index f155139e51..c49592eae8 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -809,8 +809,9 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth), IdxSigned, "idxprom"); - // We know that the pointer points to a type of the correct size, unless the - // size is a VLA. + // We know that the pointer points to a type of the correct size, + // unless the size is a VLA or Objective-C interface. + llvm::Value *Address = 0; if (const VariableArrayType *VAT = getContext().getAsVariableArrayType(E->getType())) { llvm::Value *VLASize = VLASizeMap[VAT]; @@ -823,10 +824,25 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { Idx = Builder.CreateUDiv(Idx, llvm::ConstantInt::get(Idx->getType(), BaseTypeSize)); + Address = Builder.CreateGEP(Base, Idx, "arrayidx"); + } else if (const ObjCInterfaceType *OIT = + dyn_cast<ObjCInterfaceType>(E->getType())) { + llvm::Value *InterfaceSize = + llvm::ConstantInt::get(Idx->getType(), + getContext().getTypeSize(OIT) / 8); + + Idx = Builder.CreateMul(Idx, InterfaceSize); + + llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); + Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy), + Idx, "arrayidx"); + Address = Builder.CreateBitCast(Address, Base->getType()); + } else { + Address = Builder.CreateGEP(Base, Idx, "arrayidx"); } QualType T = E->getBase()->getType()->getAsPointerType()->getPointeeType(); - LValue LV = LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"), + LValue LV = LValue::MakeAddr(Address, T.getCVRQualifiers(), getContext().getObjCGCAttrKind(T)); if (getContext().getLangOptions().ObjC1 && |