GCC 4.8.1 prerelease (x86_64 for both linux and darwin12) miscompiles the following code with optimize option "-O1 -ftree-vrp." $ cat error.c /* UINT_MAX == 4294967295 */ short x = 1; int y = 0; int main (void) { unsigned t = ( 2147450881U - (unsigned) x ) << ( y == 0 ); if ( t != 4294901760U ) { __builtin_abort(); } return 0; } $ x86_64-unknown-linux-gnu-gcc-4.8.1 error.c -O1 -ftree-vrp $ ./a.out Aborted (core dumped) There was no problem with GCC 4.7.3. ----- $ x86_64-unknown-linux-gnu-gcc-4.8.1 -v Target: x86_64-unknown-linux-gnu Configured with: /home/hassy/gcc/configure --prefix=/usr/local/x86_64-tools/gcc-4.8.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 4.8.1 20130422 (prerelease) (GCC) $ gcc-mp-4.8 -v Using built-in specs. COLLECT_GCC=gcc-mp-4.8 COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.1/lto-wrapper Target: x86_64-apple-darwin12 Configured with: ../gcc-4.8-20130411/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.8 --with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc48 4.8-20130411_0' Thread model: posix gcc version 4.8.1 20130411 (prerelease) (MacPorts gcc48 4.8-20130411_0)
Started with http://gcc.gnu.org/r191057 , looking into it.
Created attachment 29948 [details] gcc49-pr57083.patch Untested fix. llshift method always sign-extends the double_int, so we need to zero extend it manually. Thanks for the report.
Author: jakub Date: Mon Apr 29 07:55:09 2013 New Revision: 198388 URL: http://gcc.gnu.org/viewcvs?rev=198388&root=gcc&view=rev Log: PR tree-optimization/57083 * tree-vrp.c (extract_range_from_binary_expr_1): For LSHIFT_EXPR with non-singleton shift count range, zero extend low_bound for uns case. * gcc.dg/torture/pr57083.c: New test. Added: trunk/gcc/testsuite/gcc.dg/torture/pr57083.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-vrp.c Author: jakub Date: Mon Apr 29 07:57:02 2013 New Revision: 198389 URL: http://gcc.gnu.org/viewcvs?rev=198389&root=gcc&view=rev Log: PR tree-optimization/57083 * tree-vrp.c (extract_range_from_binary_expr_1): For LSHIFT_EXPR with non-singleton shift count range, zero extend low_bound for uns case. * gcc.dg/torture/pr57083.c: New test. Added: branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr57083.c Modified: branches/gcc-4_8-branch/gcc/ChangeLog branches/gcc-4_8-branch/gcc/testsuite/ChangeLog branches/gcc-4_8-branch/gcc/tree-vrp.c