http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57209
Bug #: 57209
Summary: Wrong code of print statement
Classification: Unclassified
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
The following code is miscompiled by GCC 4.8.1 20130508 (prerelease)
for x86_64 (as well as for i686). The option in question is
"-funsafe-math-optimizations."
$ cat error.c
volatile char buff = 0;
void PRINTF(const char* s)
{
while(*s++) buff = *s;
}
int main (void)
{
int k = -1;
int t = 1 % (int)(( 942.0 + k ) / -941.0F );
if (t == 0) { PRINTF("OK"); }
return 0;
}
$ x86_64-unknown-linux-gnu-gcc-4.8.1 error.c -O1 -funsafe-math-optimizations
$ ./a.out
Floating point exception (core dumped)
-----
$ x86_64-unknown-linux-gnu-gcc-4.8.1 -v
Using built-in specs.
COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-4.8.1
COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/hassy/gcc/configure
--prefix=/usr/local/x86_64-tools/gcc-4.8.1/
--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 20130508 (prerelease) (GCC)