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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285316
91177308-0d34-0410-b5e6-
96231b3b80d8
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: {
void capture(void *);
void test_alloca(int n) {
capture(_alloca(n));
- // CHECK: %[[arg:.*]] = alloca i8, i32 %
+ // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
// CHECK: call void @capture(i8* %[[arg]])
}