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

             Bug #: 54027
           Summary: possible mis-optimization of signed left shift in c89
                    mode
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: reg...@cs.utah.edu


The program below is clearly undefined in C99, but I'm not sure that it should
be undefined in C89 mode.

GCC pre-4.8.0 turns the code into an infinite loop even in C89 mode at -O2 and
higher.

regehr@home:~/svn/code$ cat shift.c
int main (void)
{
  int x = 1;
  while (x)
    x <<= 1;
  return x;
}
regehr@home:~/svn/code$ gcc -O2 -std=c89 shift.c ; ./a.out 
^C
regehr@home:~/svn/code$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/regehr/z/compiler-install/gcc-r189449-install/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/regehr/z/compiler-source/gcc/configure
--with-libelf=/usr/local --enable-lto
--prefix=/home/regehr/z/compiler-install/gcc-r189449-install
--enable-languages=c,c++
Thread model: posix
gcc version 4.8.0 20120713 (experimental) (GCC)

Reply via email to