https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112302
Bug ID: 112302 Summary: The Os optimisation level removes variable value being set in a particular instance Product: gcc Version: 12.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barryns86 at gmail dot com Target Milestone: --- Created attachment 56478 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56478&action=edit intermediate build output When I compile with optimization Os I am getting an over optimization that breaks my cpp code (variable value is not being set correctly), and I don't see the issue with O1, O2, or O3. Also Os does not produce the issue on 10.3 (my current compiler), or earlier versions. but does in all versions of 11 and 12 (that I have tried up to 12.3), and I am trying to update the compiler for a separate reason. I even tried doing O2 but setting the fno version of the flags that Os says it does not include. That still worked. In the code, The second parameter (v2) to sub_func2 (within function 1) should be 25348, not 24580. The thing that is not happening is that variable b4 should be set to 6, but its not. Its set to zero, no matter what value of "mode" is passed to function1. I tried to simplify this example down as much as I can. If you need me to try something else, or need any more info, please ask. Here is my compile line for the test version of my issue. g++ -v -save-temps -Os test.cc -o test Attached in the ii file produced with 11.4.1 and the issue is present. And here is the output from the build: Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-host-pie --enable-host-bind-now --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --enable-initfini-array --without-isl --enable-multilib --with-linker-hash-style=gnu --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_64=x86-64-v2 --with-arch_32=x86-64 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.4.1 20230605 (Red Hat 11.4.1-2) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Os' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=x86-64-v2' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1plus -E -quiet -v -D_GNU_SOURCE test.cc -mtune=generic -march=x86-64-v2 -Os -fpch-preprocess -o test.ii