public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39417]  New: Incorrect values computed with -ftree-copy-prop
@ 2009-03-09 23:18 maksverver at geocities dot com
  2009-03-09 23:19 ` [Bug c++/39417] " maksverver at geocities dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: maksverver at geocities dot com @ 2009-03-09 23:18 UTC (permalink / raw)
  To: gcc-bugs

Attached is a small program that computes some values and puts them in a
std::vector. The values are stored in the `init' variable, but when
optimizations are enabled, the data actually added to the vector is garbage.

I've done a little testing and the problem exists when compiling with -O and
-O2, but when compiling with -O0 or -O -fno-tree-copy-prop the bug disappears.
(This is also the case when compiling with -fmudflap.)

To reproduce the bug, take the attached test.cpp and do:
  $ g++ -O -o broken test.cpp
  $ ./broken
  broken: test.cpp:55: int main(): Assertion `res[0] == 5' failed.
  Aborted

For comparison, you can run:
  $ g++ -O -fno-tree-copy-prop -o working test.cpp
  $ ./working

And see that it works fine. Running the broken binary trough valgrind gives a
"conditional jump or move depends on uninitialised value" message.

I'll attach (part of) the output of compiling with -fdump-tree-optimized. The
code is similar in both versions, but I think the problem is here:

<bb 16>:
  init_lsm.129 = l / i - i / 2;
  if (init_lsm.129 >= 0)
    goto <bb 17>;
  else
    goto <bb 25>;

<bb 17>:
  init = init_lsm.129;
  init = init_lsm.130;

As you can see, the correct value in `init_lsm.129' is assigned to `init' only
to be overwritten by the uninitialized data in `init_lsm.130'. The working
version looks similar but seems to have the last two statements reversed, so
that the correct value ends up in `init'.

I'm using gcc version 4.3.3 (Gentoo 4.3.3 p1.0, pie-10.1.5), but the problem
was first seen on a system runing GCC 4.1.x (or lower); not my own system so I
can't check exactly, but it probably doesn't matter. Since the bug seems to be
in the C++ front-end, it occurs when producing 64-bit as well as 32-bit
binaries.

Hopefully, you are able to figure out what goes wrong. If this is a genuine
bug, it seems to affect a wide range of compiler versions. Let me know if you
need any more information, and I'll be happy to help.


-- 
           Summary: Incorrect values computed with -ftree-copy-prop
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: maksverver at geocities dot com
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/39417] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
@ 2009-03-09 23:19 ` maksverver at geocities dot com
  2009-03-09 23:21 ` maksverver at geocities dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: maksverver at geocities dot com @ 2009-03-09 23:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from maksverver at geocities dot com  2009-03-09 23:19 -------
Created an attachment (id=17431)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17431&action=view)
The test case that fails


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/39417] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
  2009-03-09 23:19 ` [Bug c++/39417] " maksverver at geocities dot com
@ 2009-03-09 23:21 ` maksverver at geocities dot com
  2009-03-09 23:21 ` maksverver at geocities dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: maksverver at geocities dot com @ 2009-03-09 23:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from maksverver at geocities dot com  2009-03-09 23:21 -------
Created an attachment (id=17432)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17432&action=view)
The working tree code


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/39417] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
  2009-03-09 23:19 ` [Bug c++/39417] " maksverver at geocities dot com
  2009-03-09 23:21 ` maksverver at geocities dot com
@ 2009-03-09 23:21 ` maksverver at geocities dot com
  2009-03-09 23:22 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: maksverver at geocities dot com @ 2009-03-09 23:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from maksverver at geocities dot com  2009-03-09 23:21 -------
Created an attachment (id=17433)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17433&action=view)
The broken tree code


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/39417] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (2 preceding siblings ...)
  2009-03-09 23:21 ` maksverver at geocities dot com
@ 2009-03-09 23:22 ` pinskia at gcc dot gnu dot org
  2009-03-10 11:15 ` [Bug tree-optimization/39417] [4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-03-09 23:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2009-03-09 23:22 -------
This works on the trunk.


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug tree-optimization/39417] [4.2/4.3 Regression] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (3 preceding siblings ...)
  2009-03-09 23:22 ` pinskia at gcc dot gnu dot org
@ 2009-03-10 11:15 ` rguenth at gcc dot gnu dot org
  2009-03-10 13:54 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-10 11:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-03-10 11:15 -------
Confirmed.  Workaround with -fno-tree-loop-im.

Maybe just latent on the trunk.

We perform the following:

Executing store motion of init from loop 1
Executing store motion of init from loop 1
Moving statement
init_lsm.127 = init;
(cost 0) out of loop 1.

Moving statement
init_lsm.128 = init;
(cost 0) out of loop 1.

which of course can't work.  Likely the SM rewrite on the trunk fixed this.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rakdver at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |tree-optimization
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.4 4.1.3 4.2.4 4.3.4
      Known to work|                            |3.4.6 4.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2009-03-10 11:15:32
               date|                            |
            Summary|Incorrect values computed   |[4.2/4.3 Regression]
                   |with -ftree-copy-prop       |Incorrect values computed
                   |                            |with -ftree-copy-prop


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug tree-optimization/39417] [4.2/4.3 Regression] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (4 preceding siblings ...)
  2009-03-10 11:15 ` [Bug tree-optimization/39417] [4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
@ 2009-03-10 13:54 ` rguenth at gcc dot gnu dot org
  2009-03-13 23:03 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-10 13:54 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.3.4


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug tree-optimization/39417] [4.2/4.3 Regression] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (5 preceding siblings ...)
  2009-03-10 13:54 ` rguenth at gcc dot gnu dot org
@ 2009-03-13 23:03 ` rguenth at gcc dot gnu dot org
  2009-08-04 12:55 ` [Bug tree-optimization/39417] [4.3 " rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-13 23:03 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug tree-optimization/39417] [4.3 Regression] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (6 preceding siblings ...)
  2009-03-13 23:03 ` rguenth at gcc dot gnu dot org
@ 2009-08-04 12:55 ` rguenth at gcc dot gnu dot org
  2010-04-20 14:19 ` rguenth at gcc dot gnu dot org
  2010-05-22 19:00 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-04 12:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2009-08-04 12:29 -------
GCC 4.3.4 is being released, adjusting target milestone.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.4                       |4.3.5


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug tree-optimization/39417] [4.3 Regression] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (7 preceding siblings ...)
  2009-08-04 12:55 ` [Bug tree-optimization/39417] [4.3 " rguenth at gcc dot gnu dot org
@ 2010-04-20 14:19 ` rguenth at gcc dot gnu dot org
  2010-05-22 19:00 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-20 14:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2010-04-20 14:18 -------
Subject: Bug 39417

Author: rguenth
Date: Tue Apr 20 14:18:35 2010
New Revision: 158560

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158560
Log:
2010-04-20  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/39417
        * g++.dg/torture/pr39417.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr39417.C
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug tree-optimization/39417] [4.3 Regression] Incorrect values computed with -ftree-copy-prop
  2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
                   ` (8 preceding siblings ...)
  2010-04-20 14:19 ` rguenth at gcc dot gnu dot org
@ 2010-05-22 19:00 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-22 19:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2010-05-22 18:13 -------
GCC 4.3.5 is being released, adjusting target milestone.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.5                       |4.3.6


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-05-22 18:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-09 23:18 [Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop maksverver at geocities dot com
2009-03-09 23:19 ` [Bug c++/39417] " maksverver at geocities dot com
2009-03-09 23:21 ` maksverver at geocities dot com
2009-03-09 23:21 ` maksverver at geocities dot com
2009-03-09 23:22 ` pinskia at gcc dot gnu dot org
2009-03-10 11:15 ` [Bug tree-optimization/39417] [4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
2009-03-10 13:54 ` rguenth at gcc dot gnu dot org
2009-03-13 23:03 ` rguenth at gcc dot gnu dot org
2009-08-04 12:55 ` [Bug tree-optimization/39417] [4.3 " rguenth at gcc dot gnu dot org
2010-04-20 14:19 ` rguenth at gcc dot gnu dot org
2010-05-22 19:00 ` rguenth at gcc dot gnu dot org

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).