[cfe-commits] r64701 - /cfe/trunk/lib/CodeGen/CGCall.cpp

Daniel Dunbar daniel at zuster.org
Mon Feb 16 15:38:56 PST 2009


Author: ddunbar
Date: Mon Feb 16 17:38:56 2009
New Revision: 64701

URL: http://llvm.org/viewvc/llvm-project?rev=64701&view=rev
Log:
x86_64 ABI: Handle va_arg arguments with alignment > 8.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=64701&r1=64700&r2=64701&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Feb 16 17:38:56 2009
@@ -896,11 +896,22 @@
 
   // 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.





More information about the cfe-commits mailing list