https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116690

--- Comment #1 from Yunbo Ni <yunboni at smail dot nju.edu.cn> ---
(In reply to Yunbo Ni from comment #0)
> Created attachment 59101 [details]
> 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)

Sorry, the gcc v11.1 details can be found here: https://godbolt.org/z/41Y6YG6bY
The previous link uses the latest version to compile.

Reply via email to