[cfe-commits] Alignment of return from __builtin_alloca

David Sehr sehr at google.com
Thu Jun 7 14:23:13 PDT 2012


All,

I have recently been debugging a failure with one of the tests from
the gcc torture test suite and discovered that gcc and llvm seem to
differ on whether __builtin_alloca is aligned more than 0mod4 (gcc
thinks it's aligned by what clang stores inTargetInfo::SuitableAlign).
 Below is a patch that (1) changes the alignment of __builtin_alloca
for all targets, (2) adds setting SuitableAlign to the PNaCl target,
and (3) fixes the size and alignment of v128 for PNaCl.  Please let me
know how to proceed.

David

----
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp (revision 158168)
+++ lib/Basic/Targets.cpp (working copy)
@@ -3888,6 +3888,7 @@
     this->LongWidth = 32;
     this->PointerAlign = 32;
     this->PointerWidth = 32;
+    this->SuitableAlign = 128;
     this->IntMaxType = TargetInfo::SignedLongLong;
     this->UIntMaxType = TargetInfo::UnsignedLongLong;
     this->Int64Type = TargetInfo::SignedLongLong;
@@ -3899,7 +3900,7 @@
     this->IntPtrType = TargetInfo::SignedInt;
     this->RegParmMax = 2;
     DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
-                        "f32:32:32-f64:64:64-p:32:32:32-v128:32:32";
+                        "f32:32:32-f64:64:64-p:32:32:32-v128:128:128";
   }

   void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp (revision 158168)
+++ lib/CodeGen/CGBuiltin.cpp (working copy)
@@ -536,7 +536,9 @@
   case Builtin::BIalloca:
   case Builtin::BI__builtin_alloca: {
     Value *Size = EmitScalarExpr(E->getArg(0));
-    return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+    AllocaInst *Alloca = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+    Alloca->setAlignment(CGM.getTarget().getSuitableAlign() / 8);
+    return RValue::get(Alloca);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {



More information about the cfe-commits mailing list