[llvm-commits] [llvm-gcc-4.2] r102561 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Apr 28 16:42:58 PDT 2010


Author: stoklund
Date: Wed Apr 28 18:42:58 2010
New Revision: 102561

URL: http://llvm.org/viewvc/llvm-project?rev=102561&view=rev
Log:
Obey the alignment specified on byval arguments.

This could cause problems in a function like this:

  typedef struct {
      long double location;
      long double length;
  } mstr;

  mstr x;

  void bar(int i, int j, mstr y) {
    x = y;
  }

The %y argument to bar() has align 4:

  define void @bar(i32 %i, i32 %j, %struct.mstr* byval align 4 %y) nounwind ssp {

But a 16-byte aligned memcpy was emitted:

  call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct.mstr* @x to i8*), i8* %y1, i32 32, i32 16, i1 false)

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=102561&r1=102560&r2=102561&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Apr 28 18:42:58 2010
@@ -7395,6 +7395,13 @@
       Alignment = DECL_ALIGN(exp) / 8;
   }
 
+  // Function arguments may have extra alignment attributes.
+  if (Argument *Arg = dyn_cast<Argument>(Decl)) {
+    unsigned pa = Arg->getParent()->getParamAlignment(Arg->getArgNo()+1);
+    if (pa && pa < Alignment)
+      Alignment = pa;
+  }
+
   return LValue(BitCastToType(Decl, PTy), Alignment);
 }
 





More information about the llvm-commits mailing list