https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110446
Bug ID: 110446
Summary: [14 Regression] Wrong code at -O1/2/3/s on
x86_64-pc-linux-gnu
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jwzeng at nuaa dot edu.cn
Target Milestone: ---
Link to the Compiler Explorer: https://godbolt.org/z/jE9fxsYfE
The following code snippet:
#include <stdio.h>
unsigned int a = 1387579096U;
int main() {
a = 1 < (~a) ? 1 : (~a);
printf("%u\n", a);
return 0;
}
> $ /usr/gcc-trunk/bin/gcc -O0 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O1 bug.c; ./a.out
> 2907388199
> $ /usr/gcc-trunk/bin/gcc -O2 bug.c; ./a.out
> 2907388199
> $ /usr/gcc-trunk/bin/gcc -O3 bug.c; ./a.out
> 2907388199
> $ /usr/gcc-trunk/bin/gcc -Os bug.c; ./a.out
> 2907388199
When compiled with -O1/2/3/s, it prints the wrong result 2907388199 instead of
1. Earlier GCCs do not have this bug.
> $ /usr/gcc-trunk/bin/gcc --version
Using built-in specs.
COLLECT_GCC=/home/compilers/gcc/gcc-trunk/bin/gcc
COLLECT_LTO_WRAPPER=/home/compilers/gcc/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk-source/gcc/configure
--enable-languages=c,c++,fortran --enable-checking=release
--enable-valgrind-annotations --disable-werror --disable-libstdcxx-pch
--enable-libgomp --enable-lto --enable-gold --with-plugin-ld=gold
--prefix=/usr/local/gcc-trunk
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230619 (experimental) [master r14-1917-gf8e0270272] (GCC)