forked from OSchip/llvm-project
[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
This commit is contained in:
parent
07c915e1d5
commit
1878da43ea
|
@ -1139,7 +1139,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
||||||
case Builtin::BI_alloca:
|
case Builtin::BI_alloca:
|
||||||
case Builtin::BI__builtin_alloca: {
|
case Builtin::BI__builtin_alloca: {
|
||||||
Value *Size = EmitScalarExpr(E->getArg(0));
|
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::BIbzero:
|
||||||
case Builtin::BI__builtin_bzero: {
|
case Builtin::BI__builtin_bzero: {
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
void capture(void *);
|
void capture(void *);
|
||||||
void test_alloca(int n) {
|
void test_alloca(int n) {
|
||||||
capture(_alloca(n));
|
capture(_alloca(n));
|
||||||
// CHECK: %[[arg:.*]] = alloca i8, i32 %
|
// CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
|
||||||
// CHECK: call void @capture(i8* %[[arg]])
|
// CHECK: call void @capture(i8* %[[arg]])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue