diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-16 23:38:56 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-16 23:38:56 +0000 |
commit | c5bcee4dce79458c4f490490c71619e06cbde357 (patch) | |
tree | 5f70a3f9ea0e31e5dd97b8a1ff3a396171caa98f /lib/CodeGen/CGCall.cpp | |
parent | 396b2a22788b0134018760d6a476de1e20f81334 (diff) |
x86_64 ABI: Handle va_arg arguments with alignment > 8.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64701 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r-- | lib/CodeGen/CGCall.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 708c7171da..6f22adfc8c 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -896,11 +896,22 @@ static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr, // AMD64-ABI 3.5.7p5: Step 7. Align l->overflow_arg_area upwards to a 16 // byte boundary if alignment needed by type exceeds 8 byte boundary. - uint64_t Align = llvm::NextPowerOf2(CGF.getContext().getTypeAlign(Ty) / 8); + uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8; if (Align > 8) { - // Note align to type alignment instead of assuming it must be 16. - - // FIXME: Implement alignment in x86_64 va_arg. + // Note that we follow the ABI & gcc here, even though the type + // could in theory have an alignment greater than 16. This case + // shouldn't ever matter in practice. + + // overflow_arg_area = (overflow_arg_area + 15) & ~15; + llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, 15); + overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset); + llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area, + llvm::Type::Int64Ty); + llvm::Value *Mask = llvm::ConstantInt::get(llvm::Type::Int64Ty, ~15LL); + overflow_arg_area = + CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask), + overflow_arg_area->getType(), + "overflow_arg_area.align"); } // AMD64-ABI 3.5.7p5: Step 8. Fetch type from l->overflow_arg_area. |