https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108599
Bug ID: 108599 Summary: Incorrect code generation newer intel architectures for gcc 12 and 13 Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: balder at yahooinc dot com Target Milestone: --- The code fragment below generates incorrect code for some architectures. It works fine when compiled with c++ -Wall -Wextra -O2 -march=haswell -mtune=skylake test.cpp && ./a.out Changing -mtune to skylake-avx512 makes it fail. It also fails cascadelake and icelake-client and icelake-server. It fails with both -O2 and -O3, but works fine with -O1 and -Og. c++ -Wall -Wextra -O2 -march=haswell -mtune=skylake-avx512 test.cpp && ./a.out a.out: test.cpp:23: void assert_stats(size_t, size_t, size_t, size_t, Stats): Assertion `exp_dead == stats._dead' failed. Compiler version: c++ -v Using built-in specs. COLLECT_GCC=c++ COLLECT_LTO_WRAPPER=/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/gcc-toolset-12/root/usr --mandir=/opt/rh/gcc-toolset-12/root/usr/share/man --infodir=/opt/rh/gcc-toolset-12/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-12.1.1-20220628/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.1.1 20220628 (Red Hat 12.1.1-3) (GCC) ------------------------ Code -------------------- #include <cstddef> #include <cassert> struct Stats { size_t _used; size_t _hold; size_t _dead; size_t _extra_used; Stats() : _used(0), _hold(0), _dead(0), _extra_used(0) {} Stats used(size_t val) { _used += val; return *this; } Stats hold(size_t val) { _hold += val; return *this; } }; void assert_stats(size_t exp_used, size_t exp_hold, size_t exp_dead, size_t exp_extra_used, const Stats stats) { assert(exp_used == stats._used); assert(exp_hold == stats._hold); assert(exp_dead == stats._dead); // <===== Assert fails assert(exp_extra_used == stats._extra_used); } int main(int , char* []) { assert_stats(16, 0, 0, 0, Stats().used(16).hold(0)); assert_stats(16, 16, 0, 0, Stats().used(16).hold(16)); // <========= Causes assert to fail return 0; }