public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "shcherbakov at daad-alumni dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/42722]  New: move_by_pieces() incorrectly pushes structures to stack
Date: Wed, 13 Jan 2010 09:44:00 -0000	[thread overview]
Message-ID: <bug-42722-18129@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2010-01-13  9:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-13  9:44 shcherbakov at daad-alumni dot de [this message]
2010-01-30 15:34 ` [Bug middle-end/42722] " steven at gcc dot gnu dot org
2010-01-30 15:37 ` shcherbakov at daad-alumni dot de
2010-01-30 16:01 ` rguenth at gcc dot gnu dot org
2010-01-30 19:54 ` mikpe at it dot uu dot se
2010-01-30 20:08 ` shcherbakov at daad-alumni dot de
2010-01-30 21:24 ` mikpe at it dot uu dot se
2010-01-30 21:30 ` shcherbakov at daad-alumni dot de
2010-01-30 21:57 ` mikpe at it dot uu dot se
2010-01-30 22:48 ` shcherbakov at daad-alumni dot de
2010-02-09  8:58 ` mikpe at it dot uu dot se
2010-02-10 12:45 ` shcherbakov at daad-alumni dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-42722-18129@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).