[Bug rtl-optimization/115049] [14/15 Regression] Silent severe miscompilation around inline functions
lh_mouse at 126 dot com
gcc-bugzilla@gcc.gnu.org
Sun Jul 14 09:45:36 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115049
--- Comment #9 from LIU Hao <lh_mouse at 126 dot com> ---
Created attachment 58656
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58656&action=edit
reduced testcase
After spending four days on this, I have reduced a testcase. `./test.sh` should
reproduce the segfault.
The bug exists around the initialization of a global variable in 'file2.cpp':
```
auto e = new std::discard_block_engine< int >;
```
We compile this file:
```
g++ -O2 -S -masm=intel file2.cpp
```
which produces
```
call "_Znwy" # %rax = ::operator
new
mov rcx, QWORD PTR "e"[rip] # %rcx = &e
mov r10, rax # %r10 = %rax
call "_ZNSt20discard_block_engineIiEclEv" #
std::discard_block_engine<int>::operator()(%rcx)
# -> `this` is passed
via %rcx.
mov QWORD PTR "d"[rip], r10 # d = %r10
# -> BUG. %r10 has
been clobbered by the above call
# and now contains
a garbage value.
mov DWORD PTR [r10], eax # *(DWORD*)%r10 = %eax
# -> this faults.
```
More information about the Gcc-bugs
mailing list