summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGBuiltin.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-10-31 05:37:48 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-10-31 05:37:48 +0000
commit5116993f8ea7edb4aef41cbaa9d66d1b071e02c8 (patch)
tree1a0e8839eb4c558018721f7f81a81c2805529bbb /clang/lib/CodeGen/CGBuiltin.cpp
parentdc586c4ee42f3ba0d35d4578e6230b88ac96eaeb (diff)
downloadbcm5719-llvm-5116993f8ea7edb4aef41cbaa9d66d1b071e02c8.tar.gz
bcm5719-llvm-5116993f8ea7edb4aef41cbaa9d66d1b071e02c8.zip
Add support for __builtin_alloca_with_align
__builtin_alloca always uses __BIGGEST_ALIGNMENT__ for the alignment of the allocation. __builtin_alloca_with_align allows the programmer to specify the alignment of the allocation. This fixes PR30658. llvm-svn: 285544
Diffstat (limited to 'clang/lib/CodeGen/CGBuiltin.cpp')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c73a6e1b061..54566aa7e51 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1147,6 +1147,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
AI->setAlignment(SuitableAlignmentInBytes);
return RValue::get(AI);
}
+
+ case Builtin::BI__builtin_alloca_with_align: {
+ Value *Size = EmitScalarExpr(E->getArg(0));
+ Value *AlignmentValue = EmitScalarExpr(E->getArg(1));
+ auto *AlignmentCI = cast<ConstantInt>(AlignmentValue);
+ unsigned Alignment = AlignmentCI->getZExtValue();
+ const TargetInfo &TI = getContext().getTargetInfo();
+ unsigned AlignmentInBytes = Alignment / TI.getCharWidth();
+ AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+ AI->setAlignment(AlignmentInBytes);
+ return RValue::get(AI);
+ }
+
case Builtin::BIbzero:
case Builtin::BI__builtin_bzero: {
Address Dest = EmitPointerWithAlignment(E->getArg(0));
OpenPOWER on IntegriCloud