[Bug c++/39417] New: Incorrect values computed with -ftree-copy-prop
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
[Bug c++/39417] Incorrect values computed with -ftree-copy-prop
--- 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=17431action=view) The test case that fails -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39417
[Bug c++/39417] Incorrect values computed with -ftree-copy-prop
--- 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=17432action=view) The working tree code -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39417
[Bug c++/39417] Incorrect values computed with -ftree-copy-prop
--- 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=17433action=view) The broken tree code -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39417
[Bug c++/37093] [4.2/4.3/4.4 Regression] ICE with pointer to member template parameters
--- Comment #5 from maksverver at geocities dot com 2008-08-22 16:53 --- Excuse me, but I do not understand what makes this code invalid. Could anybody explain? If so, does this apply to all the test cases given (also for bugs that are marked as duplicates of this bug)? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37093
[Bug c++/36776] New: Internal compiler error with template/pointer to member functions
I first encountered this problem with GCC 4.3.1. With that compiler, the program compiles fine (without warnings) but crashes at runtime. I tried a recent snapshot of version 4.4 before submitting a bug report, and there an internal compiler error is produced instead. So although this bug report is filed for 4.4, a similar bug is present in at least 4.3.1 (and probably others). I don't really understand what causes the bug, so I'll just give you the source code for a (self-contained, simplified) test case that causes the internal compiler error along with my output, and hope you are able to figure it out. ;-) $ g++ -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.4-20080704/configure --prefix=/home/maks/gcc-4.4-20080704 Thread model: posix gcc version 4.4.0 20080704 (experimental) (GCC) $ g++ -c -Wall -Wextra bug.cpp bug.cpp: In function âvoid invoke() [with C = Foo, void (C::* M)() = method]â: bug.cpp:9: internal compiler error: in expand_expr_real_1, at expr.c:7279 Please submit a full bug report, with preprocessed source if appropriate. See http://gcc.gnu.org/bugs.html for instructions. -- Summary: Internal compiler error with template/pointer to member functions Product: gcc Version: 4.4.0 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=36776
[Bug c++/36776] Internal compiler error with template/pointer to member functions
--- Comment #1 from maksverver at geocities dot com 2008-07-09 20:57 --- Created an attachment (id=15881) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15881action=view) The test case that produces the output described in the bug summary. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36776