diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-10-27 17:18:24 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-10-27 17:18:24 +0000 |
commit | 1878da43ea929093e9b843f375fe106b9323d4f5 (patch) | |
tree | 0d90ef67d8b7422ea98f07391b2db290057fee89 /clang/lib/CodeGen/CGBuiltin.cpp | |
parent | 07c915e1d59f981b6fc2e7f7529ca6d4f57018cb (diff) | |
download | bcm5719-llvm-1878da43ea929093e9b843f375fe106b9323d4f5.tar.gz bcm5719-llvm-1878da43ea929093e9b843f375fe106b9323d4f5.zip |
[CodeGen] Provide an appropriate alignment for dynamic allocas
GCC documents __builtin_alloca as aligning the storage to at least
__BIGGEST_ALIGNMENT__.
MSVC documents essentially the same for the x64 ABI:
https://msdn.microsoft.com/en-us/library/x9sx5da1.aspx
The 32-bit ABI follows the same rule: it emits a call to _alloca_probe_16
Differential Revision: https://reviews.llvm.org/D24378
llvm-svn: 285316
Diffstat (limited to 'clang/lib/CodeGen/CGBuiltin.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 5bbc9ea5341..c73a6e1b061 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1139,7 +1139,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BI_alloca: case Builtin::BI__builtin_alloca: { Value *Size = EmitScalarExpr(E->getArg(0)); - return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size)); + const TargetInfo &TI = getContext().getTargetInfo(); + // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__. + unsigned SuitableAlignmentInBytes = + TI.getSuitableAlign() / TI.getCharWidth(); + AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); + AI->setAlignment(SuitableAlignmentInBytes); + return RValue::get(AI); } case Builtin::BIbzero: case Builtin::BI__builtin_bzero: { |