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 | bc8d40d85f3fa1e34569834916f18fecaa635152 (patch) | |
tree | 47e76a7172c2f2244ee4bbe5fe71fc0bf65e63d3 /lib/CodeGen/CGExpr.cpp | |
parent | 89f19e43730a2895cd81159d375c71c91872b8c2 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133827 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index af0af7fbef..e8d156ea64 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/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 = |