summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorJames Y Knight <jyknight@google.com>2015-08-21 18:19:06 +0000
committerJames Y Knight <jyknight@google.com>2015-08-21 18:19:06 +0000
commit7160857da377e50d42b7d892844428c78338c696 (patch)
treea9f77aaa231eb3e173ae96e05b9c708eba858a64 /clang/lib
parent1e3dc527ea6d548bd776896d6fe73a91754d762e (diff)
downloadbcm5719-llvm-7160857da377e50d42b7d892844428c78338c696.tar.gz
bcm5719-llvm-7160857da377e50d42b7d892844428c78338c696.zip
Properly provide alignment of 'byval' arguments down to llvm.
This is important in the case that the LLVM-inferred llvm-struct alignment is not the same as the clang-known C-struct alignment. Differential Revision: http://reviews.llvm.org/D12243 llvm-svn: 245719
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a5802346d4a..f40dd086481 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1663,20 +1663,35 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
Attrs.addAttribute(llvm::Attribute::InReg);
break;
- case ABIArgInfo::Indirect:
+ case ABIArgInfo::Indirect: {
if (AI.getInReg())
Attrs.addAttribute(llvm::Attribute::InReg);
if (AI.getIndirectByVal())
Attrs.addAttribute(llvm::Attribute::ByVal);
- Attrs.addAlignmentAttr(AI.getIndirectAlign());
+ unsigned Align = AI.getIndirectAlign();
+
+ // In a byval argument, it is important that the required
+ // alignment of the type is honored, as LLVM might be creating a
+ // *new* stack object, and needs to know what alignment to give
+ // it. (Sometimes it can deduce a sensible alignment on its own,
+ // but not if clang decides it must emit a packed struct, or the
+ // user specifies increased alignment requirements.)
+ //
+ // This is different from indirect *not* byval, where the object
+ // exists already, and the align attribute is purely
+ // informative.
+ if (Align == 0 && AI.getIndirectByVal())
+ Align = getContext().getTypeAlignInChars(ParamType).getQuantity();
+
+ Attrs.addAlignmentAttr(Align);
// byval disables readnone and readonly.
FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
.removeAttribute(llvm::Attribute::ReadNone);
break;
-
+ }
case ABIArgInfo::Ignore:
case ABIArgInfo::Expand:
continue;
OpenPOWER on IntegriCloud