https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112289
--- Comment #4 from xiao xiang <Sean.XiaoXiang at outlook dot com> --- --------------- description ---------------- some store instructions will be lost under certain conditions. 1、 GCC version >= 12.1 2、 Optimization enable at ‘-Os’ (actually is -fstore-merging) 3、 Code like the sample below We also had some tests and the results (based on GCC version 13.2.0) Fails with -Os Passes with -Os -fno-store-merging Passes with -Os -fno-ipa-modref Passes with -Os -fno-ssa-phiopt Passes with -Os -fno-tree-dse Passes with -Os -fno-tree-pta Passes with -O1 Fails with -O1 -fstore-merging ---------------Sample code merge.c ---------------- #include <stdio.h> typedef union { struct { int bit0:1; int bit1:1; int bit2:1; }; int data; } BITS; void init(BITS *val, int flag) { val->bit1 = 1; val->bit2 = 1; if (flag > 1) { val->bit2 = 0; } return; } int main(int argc, char **argv) { (void)argv; BITS value; value.data = 0; value.bit0 = 1; // lost instrument init(&value, argc); printf("%x\n", value); return 0; } --------------- command line ---------------- --------------- compile option ---------------- --------------- expected and actual behavior ---------------- $ gcc -Os merge.c $ ./a.exe 6 <--------- expect 7, but bit0 not set --------------- system ---------------- windows 10 with mingw64 Linux x86_64 tested the same --------------- gcc version ---------------- $ gcc -v Using built-in specs. COLLECT_GCC=D:\mingw64\bin\gcc.exe COLLECT_LTO_WRAPPER=D:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-13.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64--with-sysroot=/c/buildroot/x86_64-1320-posix-seh-msvcrt-rt_v11-rev0/mingw64 --enable-host-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-libssp --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-Builds project' --with-bugurl=https://github.com/niXman/mingw-builds CFLAGS='-O2 -pipe -fno-ident -I/c/buildroot/x86_64-1320-posix-seh-msvcrt-rt_v11-rev0/mingw64/opt/include -I/c/buildroot/prerequisites/x86_64-zlib-static/include -I/c/buildroot/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/buildroot/x86_64-1320-posix-seh-msvcrt-rt_v11-rev0/mingw64/opt/include -I/c/buildroot/prerequisites/x86_64-zlib-static/include -I/c/buildroot/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/buildroot/x86_64-1320-posix-seh-msvcrt-rt_v11-rev0/mingw64/opt/include -I/c/buildroot/prerequisites/x86_64-zlib-static/include -I/c/buildroot/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/buildroot/x86_64-1320-posix-seh-msvcrt-rt_v11-rev0/mingw64/opt/lib -L/c/buildroot/prerequisites/x86_64-zlib-static/lib -L/c/buildroot/prerequisites/x86_64-w64-mingw32-static/lib ' LD_FOR_TARGET=/c/buildroot/x86_64-1320-posix-seh-msvcrt-rt_v11-rev0/mingw64/bin/ld.exe --with-boot-ldflags=' -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.2.0 (x86_64-posix-seh-rev0, Built by MinGW-Builds project)