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

            Bug ID: 60971
           Summary: Wrong code when coercing unsigned char to bool
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter at empeg dot com

GCC 4.9.0 for x86_64 produces the wrong code for bar1 given this C++ file:

unsigned char foo();
bool bar1() { return foo() & 1; }
bool bar2() { return foo() & 2; }

gcc -O2 -S gcc49.cpp -Wall -Wextra

bar1 is compiled into a direct tailcall to foo() -- no and'ing with 1 is done
to the result (so it returns the Wrong Thing if foo() returns 0x40, say). bar2
is correct however.

GCC 4.8.2 got this right (its output for bar1 and bar2 is very similar except
for the constant being and'ed with).

GCC 4.9.0 gets it right if "unsigned char" is replaced with "unsigned short" or
"unsigned int".

4.9.0 built from release tarball, configured --enable-shared \
            --enable-languages=c,c++ --disable-werror \
            --enable-threads --disable-multilib \
            --enable-__cxa_atexit --with-system-zlib

When GCC was compiled, CFLAGS, LIBCFLAGS, LIBCXXFLAGS, and BOOT_CFLAGS were all
set to "-O2 -O9 -march=core2 -mtune=core2 -pipe".

Reply via email to