public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/98847] New: Miscompilation with c++17, templates, and register keyword
@ 2021-01-27  5:22 programmerjake at gmail dot com
  2021-01-27  7:56 ` [Bug inline-asm/98847] " rguenth at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: programmerjake at gmail dot com @ 2021-01-27  5:22 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-09-11 14:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27  5:22 [Bug inline-asm/98847] New: Miscompilation with c++17, templates, and register keyword programmerjake at gmail dot com
2021-01-27  7:56 ` [Bug inline-asm/98847] " rguenth at gcc dot gnu.org
2021-01-27  8:17 ` pinskia at gcc dot gnu.org
2021-01-27 10:05 ` jakub at gcc dot gnu.org
2021-01-27 16:07 ` programmerjake at gmail dot com
2021-01-28 15:14 ` cvs-commit at gcc dot gnu.org
2021-01-28 15:29 ` krebbel at gcc dot gnu.org
2021-01-29 19:20 ` cvs-commit at gcc dot gnu.org
2021-02-01 20:42 ` programmerjake at gmail dot com
2021-04-20 23:31 ` cvs-commit at gcc dot gnu.org
2021-04-22 16:50 ` cvs-commit at gcc dot gnu.org
2021-04-22 17:10 ` jakub at gcc dot gnu.org
2021-04-22 19:01 ` programmerjake at gmail dot com
2021-09-11 14:29 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).