diff options
author | John McCall <rjmccall@apple.com> | 2011-06-24 21:55:10 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-06-24 21:55:10 +0000 |
commit | 23c29fea92a130313bd389f23a696165eae4a36b (patch) | |
tree | eb365d076c07900ff896e24907685ec3fb80dcc0 /clang/lib/CodeGen/CGExpr.cpp | |
parent | 932e5b5d52be4f901bf5370ee6d98349ee209643 (diff) | |
download | bcm5719-llvm-23c29fea92a130313bd389f23a696165eae4a36b.tar.gz bcm5719-llvm-23c29fea92a130313bd389f23a696165eae4a36b.zip |
Change the IR-generation of VLAs so that we capture bounds,
not sizes; so that we use well-typed allocas; and so that we
properly recurse through the full set of variably-modified types.
llvm-svn: 133827
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index af0af7fbefd..e8d156ea64d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1579,21 +1579,22 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { // size is a VLA or Objective-C interface. llvm::Value *Address = 0; unsigned ArrayAlignment = 0; - if (const VariableArrayType *VAT = + if (const VariableArrayType *vla = getContext().getAsVariableArrayType(E->getType())) { - llvm::Value *VLASize = GetVLASize(VAT); + // The base must be a pointer, which is not an aggregate. Emit + // it. It needs to be emitted first in case it's what captures + // the VLA bounds. + Address = EmitScalarExpr(E->getBase()); - Idx = Builder.CreateMul(Idx, VLASize); + // The element count here is the total number of non-VLA elements. + llvm::Value *numElements = getVLASize(vla).first; - // The base must be a pointer, which is not an aggregate. Emit it. - llvm::Value *Base = EmitScalarExpr(E->getBase()); + Idx = Builder.CreateMul(Idx, numElements); - Address = EmitCastToVoidPtr(Base); if (getContext().getLangOptions().isSignedOverflowDefined()) Address = Builder.CreateGEP(Address, Idx, "arrayidx"); else Address = Builder.CreateInBoundsGEP(Address, 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 = |