diff options
author | Daniel Dunbar <daniel@zuster.org> | 2011-04-01 00:49:43 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2011-04-01 00:49:43 +0000 |
commit | d553408ff15b38710a1ba0947efbf4c5637018ab (patch) | |
tree | ea11c465a957f14f3c89d9776e4979bef0808971 /lib/CodeGen/CGExpr.cpp | |
parent | 457c838b7252dd3deeec8a924dcb0e47b8c6df23 (diff) |
IRgen: Reapply r128691 with a fix to ensure we don't increase alignment past
that of the array element type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index ab88a38bab..92e6a19c25 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1424,6 +1424,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { // 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; + unsigned ArrayAlignment = 0; if (const VariableArrayType *VAT = getContext().getAsVariableArrayType(E->getType())) { llvm::Value *VLASize = GetVLASize(VAT); @@ -1459,10 +1460,14 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { // "gep x, i" here. Emit one "gep A, 0, i". assert(Array->getType()->isArrayType() && "Array to pointer decay must have array source type!"); - llvm::Value *ArrayPtr = EmitLValue(Array).getAddress(); + LValue ArrayLV = EmitLValue(Array); + llvm::Value *ArrayPtr = ArrayLV.getAddress(); llvm::Value *Zero = llvm::ConstantInt::get(Int32Ty, 0); llvm::Value *Args[] = { Zero, Idx }; + // Propagate the alignment from the array itself to the result. + ArrayAlignment = ArrayLV.getAlignment(); + if (getContext().getLangOptions().isSignedOverflowDefined()) Address = Builder.CreateGEP(ArrayPtr, Args, Args+2, "arrayidx"); else @@ -1480,7 +1485,13 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { assert(!T.isNull() && "CodeGenFunction::EmitArraySubscriptExpr(): Illegal base type"); - LValue LV = MakeAddrLValue(Address, T); + // Limit the alignment to that of the result type. + if (ArrayAlignment) { + unsigned Align = getContext().getTypeAlignInChars(T).getQuantity(); + ArrayAlignment = std::min(Align, ArrayAlignment); + } + + LValue LV = MakeAddrLValue(Address, T, ArrayAlignment); LV.getQuals().setAddressSpace(E->getBase()->getType().getAddressSpace()); if (getContext().getLangOptions().ObjC1 && |