From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4081 invoked by alias); 13 Jan 2010 09:44:02 -0000 Received: (qmail 3982 invoked by uid 48); 13 Jan 2010 09:43:48 -0000 Date: Wed, 13 Jan 2010 09:44:00 -0000 Subject: [Bug middle-end/42722] New: move_by_pieces() incorrectly pushes structures to stack X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "shcherbakov at daad-alumni dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-01/txt/msg01452.txt.bz2 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