public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/113921] Output register of an "asm volatile goto" is incorrectly clobbered/discarded
Date: Wed, 14 Feb 2024 19:07:04 +0000	[thread overview]
Message-ID: <bug-113921-4-91C6rPFYMS@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113921-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-02-14

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, GCC 11 version:
--- gcc/cfgexpand.c.jj  2023-05-09 12:59:04.381738365 +0200
+++ gcc/cfgexpand.c     2024-02-14 19:56:08.733150432 +0100
@@ -3639,7 +3639,16 @@ expand_asm_stmt (gasm *stmt)
                emit_insn (copy_insn (PATTERN (curr)));
              rtx_insn *copy = get_insns ();
              end_sequence ();
-             insert_insn_on_edge (copy, e);
+             if (rtx_insn *prev = e->insns.r)
+               {
+                 /* Prepend copy before any other previously
+                    inserted insns on the edge rather than append.  */
+                 e->insns.r = NULL;
+                 insert_insn_on_edge (copy, e);
+                 insert_insn_on_edge (prev, e);
+               }
+             else
+               insert_insn_on_edge (copy, e);
            }
        }
     }
changes the emitted assembler:
@@ -7328,7 +7328,7 @@ sync_vmcs02_to_vmcs12:
 # 0 "" 2
 #NO_APP
 .L1127:
-       xorl    %r12d, %r12d
+       movq    %rax, %r12
 .L1083:
        movq    %r12, 240(%rbx)
        jmp     .L1047
@@ -29897,7 +29897,7 @@ nested_vmx_vmexit:
 # 0 "" 2
 #NO_APP
 .L5187:
-       xorl    %r12d, %r12d
+       movq    %rax, %r12
 .L5113:
        movq    %r12, %rdx
        movl    $7, %esi
which is I believe exactly what we want.

For GCC trunk the patch would be
--- gcc/cfgexpand.cc.jj 2024-02-10 11:25:09.995474027 +0100
+++ gcc/cfgexpand.cc    2024-02-14 19:54:30.811505882 +0100
@@ -3687,7 +3687,16 @@ expand_asm_stmt (gasm *stmt)
                  copy = get_insns ();
                  end_sequence ();
                }
-             insert_insn_on_edge (copy, e);
+             if (rtx_insn *prev = e->insns.r)
+               {
+                 /* Prepend copy before any other previously
+                    inserted insns on the edge rather than append.  */
+                 e->insns.r = NULL;
+                 insert_insn_on_edge (copy, e);
+                 insert_insn_on_edge (prev, e);
+               }
+             else
+               insert_insn_on_edge (copy, e);
            }
        }
     }
and with trunk it triggers (I mean the prev != NULL case) only on the
nested_vmx_vmexit
function and not the other one.
Guess one could try to build whole kernel with instrumented gcc (just add
FILE *f = fopen ("/tmp/asmgoto", "a");
fprintf (f, "%s %s\n", main_input_filename ? main_input_filename : "-",
current_function_name ());
fclose (f);
next to the e->insns.r = NULL; in the patch or so) to find out what else it
affects.

  parent reply	other threads:[~2024-02-14 19:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 17:19 [Bug c/113921] New: " seanjc at google dot com
2024-02-14 18:00 ` [Bug middle-end/113921] " jakub at gcc dot gnu.org
2024-02-14 18:13 ` torvalds@linux-foundation.org
2024-02-14 18:16 ` torvalds@linux-foundation.org
2024-02-14 18:21 ` jakub at gcc dot gnu.org
2024-02-14 18:25 ` torvalds@linux-foundation.org
2024-02-14 18:40 ` jakub at gcc dot gnu.org
2024-02-14 19:07 ` jakub at gcc dot gnu.org [this message]
2024-02-14 20:31 ` jakub at gcc dot gnu.org
2024-02-15  8:00 ` rguenth at gcc dot gnu.org
2024-02-15  8:21 ` jakub at gcc dot gnu.org
2024-02-15 14:56 ` cvs-commit at gcc dot gnu.org
2024-02-15 15:14 ` cvs-commit at gcc dot gnu.org
2024-02-15 15:17 ` cvs-commit at gcc dot gnu.org
2024-02-15 15:20 ` cvs-commit at gcc dot gnu.org
2024-02-15 15:22 ` jakub 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-113921-4-91C6rPFYMS@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).