GCC 5.0.0 for x86_64 miscompiles the following code. $ cat test.c int a = 0, b = 1, c = 0, d = 1, e, f, g, h; int main () { e = 1 >> d; f = ((31 / (1 > e)) || c) / 2; g = b || a; h = 31 / g; if (!h) __builtin_abort(); return 0; } $ x86_64-unknown-linux-gnu-gcc-5.0.0 test.c -O2 $ ./a.out Floating point exception (core dumped) $ x86_64-unknown-linux-gnu-gcc-5.0.0 -v Using built-in specs. COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-5.0.0 COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc- 5.0.0/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /home/orange3/gcc-master/configure -- prefix=/usr/local/x86_64-tools/gcc-5.0.0/ --with-gmp=/usr/local/gmp- 5.1.1/ --with-mpfr=/usr/local/mpfr-3.1.2/ --with-mpc=/usr/local/mpc- 1.0.1/ --disable-multilib --disable-nls --enable-languages=c Thread model: posix gcc version 5.0.0 20140922 (experimental) (GCC)
Works with -fno-tree-vrp. Seems to have started with r211904.
Mine.
Hmm. We end up with main () { int d.0_4; int e.1_5; int _7; int b.7_11; int a.8_12; <bb 2>: d.0_4 = d; e.1_5 = 1 >> d.0_4; e = e.1_5; _7 = 31 / 0; in the end. Which is caused by tail-merging (part of PRE) optimizing <bb 2>: d.0_4 = d; e.1_5 = 1 >> d.0_4; e = e.1_5; if (e.1_5 <= 0) goto <bb 10>; else goto <bb 3>; <bb 10>: goto <bb 4>; <bb 3>: _7 = 31 / 0; <bb 4>: by removing bb 3 as having no side-effect appearantly (_7 is unused). It produces <bb 2>: d.0_4 = d; e.1_5 = 1 >> d.0_4; e = e.1_5; <bb 3>: _7 = 31 / 0; <bb 4>: not sure how it ends up doing that (I suppose it has code to merge an if diamond).
*** Bug 63381 has been marked as a duplicate of this bug. ***
Author: rguenth Date: Thu Oct 9 12:45:07 2014 New Revision: 216038 URL: https://gcc.gnu.org/viewcvs?rev=216038&root=gcc&view=rev Log: 2014-10-09 Richard Biener <rguenther@suse.de> PR tree-optimization/63380 * tree-ssa-tail-merge.c (stmt_local_def): Exclude stmts that may trap. * gcc.dg/torture/pr63380-1.c: New testcase. * gcc.dg/torture/pr63380-2.c: Likewise. Added: trunk/gcc/testsuite/gcc.dg/torture/pr63380-1.c trunk/gcc/testsuite/gcc.dg/torture/pr63380-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-tail-merge.c
Fixed.
Author: rguenth Date: Fri Oct 10 11:05:39 2014 New Revision: 216066 URL: https://gcc.gnu.org/viewcvs?rev=216066&root=gcc&view=rev Log: 2014-10-10 Richard Biener <rguenther@suse.de> PR tree-optimization/63380 * tree-ssa-tail-merge.c (stmt_local_def): Exclude stmts that may trap. * gcc.dg/torture/pr63380-1.c: New testcase. * gcc.dg/torture/pr63380-2.c: Likewise. Added: branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/torture/pr63380-1.c branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/torture/pr63380-2.c Modified: branches/gcc-4_9-branch/gcc/ChangeLog branches/gcc-4_9-branch/gcc/testsuite/ChangeLog branches/gcc-4_9-branch/gcc/tree-ssa-tail-merge.c