[llvm-commits] [llvm-gcc-4.0] r43394 - /llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp

Bill Wendling isanbard at gmail.com
Fri Oct 26 13:20:30 PDT 2007


Author: void
Date: Fri Oct 26 15:20:29 2007
New Revision: 43394

URL: http://llvm.org/viewvc/llvm-project?rev=43394&view=rev
Log:
There are situations where the source and destination alignments differ. This
can cause havoc with memcpy. In this case, memcpy is using the alignment of the
source pointer and assuming that the destination pointer has the same
alignment. Fix this by copying the source pointer node and adjusting the
alignment to the minimum of the two alignments.


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

Modified: llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp?rev=43394&r1=43393&r2=43394&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp Fri Oct 26 15:20:29 2007
@@ -3020,8 +3020,26 @@
       Emit(TREE_OPERAND(exp, 1), LV.Ptr);
       EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), isVolatile, false,
                         Alignment);
-    } else if (!isVolatile && TREE_CODE(TREE_OPERAND(exp, 0))!=RESULT_DECL) {
-      Emit(TREE_OPERAND(exp, 1), LV.Ptr);
+    } else if (!isVolatile && TREE_CODE(TREE_OPERAND(exp, 0)) != RESULT_DECL) {
+      // At this point, Alignment is the alignment of the destination
+      // pointer. It may not match the alignment of the source pointer. So, we
+      // need to make sure that it's has at least its alignment.
+      tree new_exp = copy_node(TREE_OPERAND(exp, 1));
+      unsigned NewAlignment = expr_align(new_exp) / 8;
+      Alignment = (Alignment < NewAlignment) ? Alignment : NewAlignment;
+      TYPE_ALIGN(TREE_TYPE(new_exp)) = Alignment;
+ 
+      switch (TREE_CODE(new_exp)) {
+      case VAR_DECL:
+      case PARM_DECL:
+      case RESULT_DECL:
+ 	DECL_ALIGN (new_exp) = Alignment * 8;
+ 	break;
+      default:
+ 	break;
+      }
+ 
+      Emit(new_exp, LV.Ptr);
     } else {
       // Need to do a volatile store into TREE_OPERAND(exp, 1).  To do this, we
       // emit it into a temporary memory location, then do a volatile copy into





More information about the llvm-commits mailing list