The move_by_pieces() function incorrectly works on targets with enabled
PUSH_ARGS that support post-increment loads. To reproduce the bug, the
following code should be compiled:

struct test { int a, b, c, d, e, f; } //Enough fields to pass structure in
stack
void func2(test copy);
void func1(test copy) {func2(copy);}

Every time a copy of our big structure is pushed to stack, its fields will go
in reverse order. This happens due to a bug in move_by_pieces() function from
expr.c that generates code for pushing a memory block in stack. 
This happens because if the target supports post-increment addressing, the
USE_LOAD_POST_INCREMENT() condition is met and the memory block to be pushed is
parsed from start to end using autoincrement addressing. The "reverse" flag
specifying that the push statements should traverse the block from end to start
is then ignored.
The proposed fix explicitly disables using post-increment mode if the "reverse"
flag is set.

The following patch fixes the problem:
---------------------------------------------
--- expr.old    Thu Aug 20 00:52:11 2009
+++ expr.new    Tue Jan 12 23:32:05 2010
@@ -952,13 +952,13 @@
       if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
        {
          data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
          data.autinc_from = 1;
          data.explicit_inc_from = -1;
        }
-      if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
+      if (USE_LOAD_POST_INCREMENT (mode) && !data.reverse && !
data.autinc_from)
        {
          data.from_addr = copy_addr_to_reg (from_addr);
          data.autinc_from = 1;
          data.explicit_inc_from = 1;
        }
       if (!data.autinc_from && CONSTANT_P (from_addr))


-- 
           Summary: move_by_pieces() incorrectly pushes structures to stack
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: shcherbakov at daad-alumni dot de
 GCC build triplet: all
  GCC host triplet: all
GCC target triplet: msp430-gcc


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42722

Reply via email to