https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86699
Bug ID: 86699
Summary: Memory load optimization (-O2) bug
Product: gcc
Version: 7.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nikita.o.p at yandex dot ru
Target Milestone: ---
Created attachment 44451
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44451&action=edit
Memory ordering load bug
The bug is related to some internal code structure, so tried to reproduce the
situation as close as possible. mingw with -O2 optimization flag loads
memset-ed value on the first load of atomic (just struct name) value read and
initialized value (right value) at the second load call.
Reproducer is attached.
Fixes:
* Removing volatile keyword
* Changing int32_t to unsigned long
* Other reduction of code complexity
What is wrong with this code? Is it a bug? GCC7 does not have this issue.
I tried to open a bug on MinGW tracker, but they said, that this place is more
relevant.
Output:
Expected:0 Value first: 4294967295
Expected:0 Value second: 0
Environment:
Windows Server 2016
gcc -v Using built-in specs. COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=d:/mingwcompilers/mingw_15.4_gcc_7.3.0/bin/../libexec/gcc/x86_64-w64-mingw32/7.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32 Configured with: ../src/configure
--enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32
--target=x86_64-w64-mingw32 --disable-multilib --prefix=/c/temp/gcc/dest
--with-sysroot=/c/temp/gcc/dest --disable-libstdcxx-pch
--disable-libstdcxx-verbose --disable-nls --disable-shared
--disable-win32-registry --with-tune=haswell --enable-threads=posix
--enable-libgomp Thread model: posix gcc version 7.3.0 (GCC)
ld -v GNU ld (GNU Binutils) 2.29.1