public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "programmerjake at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug inline-asm/98847] New: Miscompilation with c++17, templates, and register keyword
Date: Wed, 27 Jan 2021 05:22:55 +0000	[thread overview]
Message-ID: <bug-98847-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2021-01-27  5:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27  5:22 programmerjake at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98847-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).