diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2011-03-31 23:32:15 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2011-03-31 23:32:15 +0000 |
| commit | b23a5a0a043b852ad643d366a0bb5b4c5a5c8881 (patch) | |
| tree | 17f8e3ec9f4b414a00f7af374a7a843171e562ab /lib/CodeGen/CGExpr.cpp | |
| parent | 822ac874ae99f326b59eb340bd47e96f69c0cf3b (diff) | |
| download | clang-b23a5a0a043b852ad643d366a0bb5b4c5a5c8881.tar.gz clang-b23a5a0a043b852ad643d366a0bb5b4c5a5c8881.tar.bz2 clang-b23a5a0a043b852ad643d366a0bb5b4c5a5c8881.tar.xz | |
IRgen: Improve GCC compatibility when dealing with packed arrays by propagating
the array alignment to the array access.
- This is more or less the best we can do without having alignment present in
the type system, but is a long way from truly matching how GCC handles this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128691 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index ab88a38bab..cd68f8fdaf 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,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { assert(!T.isNull() && "CodeGenFunction::EmitArraySubscriptExpr(): Illegal base type"); - LValue LV = MakeAddrLValue(Address, T); + LValue LV = MakeAddrLValue(Address, T, ArrayAlignment); LV.getQuals().setAddressSpace(E->getBase()->getType().getAddressSpace()); if (getContext().getLangOptions().ObjC1 && |
