https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71631
Bug ID: 71631
Summary: Wrong constant folding
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ishiura-compiler at ml dot kwansei.ac.jp
Target Milestone: ---
GCC 7.0.0 for x86_64 miscompiles the following code.
% cat test.c
volatile char buff = 0;
void PRINTF(const char* s)
{
while(*s++) buff = *s;
}
int a = 1;
int b = 1;
int c = 1;
int main (void)
{
volatile int d = 1;
volatile int e = 1;
int f = 1 / a;
int g = 1U < f;
int h = 2 + g;
int i = 3 % h;
int j = e && b;
int k = 1 == c;
int l = d != 0;
short m = (short)( -1 * i * l );
short x = j * ( k * m );
if (i == 1) {PRINTF("OK");}
if (x != -1) __builtin_abort();
return 0;
}
% gcc-7.0 test.c -O3
% ./a.out
zsh: abort (core dumped) ./a.out
% gcc-7.0 -v
Using built-in specs.
COLLECT_GCC=gcc-7.0
COLLECT_LTO_WRAPPER=/home/cappie/opt/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/cappie/opt/gcc-7.0.0 --disable-nls
--disable-multilib --program-suffix=-7.0 --enable-languages=c
Thread model: posix
gcc version 7.0.0 20160621 (experimental) (GCC)