https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98847
Bug ID: 98847
Summary: Miscompilation with c++17, templates, and register
keyword
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: inline-asm
Assignee: unassigned at gcc dot gnu.org
Reporter: programmerjake at gmail dot com
Target Milestone: ---
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
In:
https://gcc.godbolt.org/z/49xoKP
With the following code:
template <typename T = void>
int template_get_edx() {
register int edx asm("edx");
asm("movl $1234, %%edx\n\t# reg=%0" : "=r"(edx));
return edx;
}
template int template_get_edx<void>();
With: -O -Wall -std=c++17
Miscompiles, allocating %eax to the C++-level edx variable.
It's possible the C++ frontend is removing the register keyword before
finishing parsing since it also incorrectly warns here (bug #98846)
produces:
_Z16template_get_edxIvEiv:
.LFB1:
.file 1 "./example.cpp"
.loc 1 2 5 view -0
.cfi_startproc
.loc 1 4 5 is_stmt 0 view .LVU1
#APP
# 4 "./example.cpp" 1
movl $1234, %edx
# reg=%eax
# 0 "" 2
.LVL0:
.loc 1 6 1 view .LVU2
#NO_APP
ret