public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60971] New: Wrong code when coercing unsigned char to bool
@ 2014-04-26  0:36 peter at empeg dot com
  2014-04-26  9:54 ` [Bug tree-optimization/60971] [4.9/4.10 Regression] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: peter at empeg dot com @ 2014-04-26  0:36 UTC (permalink / raw)
  To: gcc-bugs

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".


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-04-30 17:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-26  0:36 [Bug c++/60971] New: Wrong code when coercing unsigned char to bool peter at empeg dot com
2014-04-26  9:54 ` [Bug tree-optimization/60971] [4.9/4.10 Regression] " jakub at gcc dot gnu.org
2014-04-29  5:06 ` law at redhat dot com
2014-04-29  9:29 ` jakub at gcc dot gnu.org
2014-04-29 10:18 ` jakub at gcc dot gnu.org
2014-04-29 13:04 ` law at redhat dot com
2014-04-29 14:44 ` jakub at gcc dot gnu.org
2014-04-29 14:46 ` jakub at gcc dot gnu.org
2014-04-30 17:36 ` law at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).