https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116690
Bug ID: 116690 Summary: Miscompile with different optimization flags Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: yunboni at smail dot nju.edu.cn Target Milestone: --- Created attachment 59101 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59101&action=edit The preprocessed file when using -O2 When I compiled this code with -O0 and -O2 flags, its outputs were different: ```c #include <stdint.h> #include <stdio.h> int32_t b = 2392213176; uint32_t e(uint32_t, uint32_t f) { return -f; } long a(int, int, int) {} int16_t c(int64_t); uint32_t d() { c(b); } int16_t c(int64_t) { for (b = 9; a(0, 0, 0) + b > 0; b = e(0, 3)) ; } int main() { d(); printf("%d\n", b); } ``` With -O0, its output is -3, while its output is 9 with -O2. I used gcc v11.1 to compile and this miscompile still exists. Details can be found here: https://godbolt.org/z/hzq99xdfj My gcc version is: Using built-in specs. COLLECT_GCC=/home/yunbo/eval/compilers/gcc_latest/bin/gcc COLLECT_LTO_WRAPPER=/home/yunbo/eval/compilers/gcc_latest/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --disable-multilib --disable-bootstrap --enable-languages=c,c++ --prefix=/home/yunbo/eval/compilers/gcc_latest Thread model: posix Supported LTO compression algorithms: zlib gcc version 15.0.0 20240909 (experimental) (GCC)