public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10828] rtl: ICE with thread_local and inline asm [PR104777]
Date: Mon, 13 Jun 2022 16:29:50 +0000 (GMT)	[thread overview]
Message-ID: <20220613162950.27608381BBC9@sourceware.org> (raw)

https://gcc.gnu.org/g:f2851a7cff4d74edca26d39c7bfa1264355a22ed

commit r10-10828-gf2851a7cff4d74edca26d39c7bfa1264355a22ed
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Mar 7 16:15:46 2022 -0500

    rtl: ICE with thread_local and inline asm  [PR104777]
    
    In r270550, Jakub fixed classify_insn to handle asm goto: if the asm can
    jump to a label, the insn should be a JUMP_INSN.
    
    However, as the following testcase shows, non-null ASM_OPERANDS_LABEL_VEC
    doesn't guarantee that the rtx has any actual labels it can branch to.
    Here, the rtvec has 0 elements because expand_asm_stmt created it:
    
      rtvec labelvec = rtvec_alloc (nlabels); // nlabels == 0
    
    This causes an ICE in update_br_prob_note: BRANCH_EDGE (bb) crashes
    because there's no branch edge.  I think we can fix this by checking
    that there is at least one label the asm can jump to before wrapping
    the ASM_OPERANDS in a JUMP_INSN.
    
            PR rtl-optimization/104777
    
    gcc/ChangeLog:
    
            * rtl.c (classify_insn): For ASM_OPERANDS, return JUMP_INSN only if
            ASM_OPERANDS_LABEL_VEC has at least one element.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/torture/tls/pr104777.c: New test.
    
    (cherry picked from commit e1133c0205a7e2a65834a1af780b8da15eead2a9)

Diff:
---
 gcc/rtl.c                                   |  4 ++--
 gcc/testsuite/gcc.dg/torture/tls/pr104777.c | 30 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gcc/rtl.c b/gcc/rtl.c
index 63f0a26c912..294206b98e2 100644
--- a/gcc/rtl.c
+++ b/gcc/rtl.c
@@ -747,7 +747,7 @@ classify_insn (rtx x)
     return CALL_INSN;
   if (ANY_RETURN_P (x))
     return JUMP_INSN;
-  if (GET_CODE (x) == ASM_OPERANDS && ASM_OPERANDS_LABEL_VEC (x))
+  if (GET_CODE (x) == ASM_OPERANDS && ASM_OPERANDS_LABEL_LENGTH (x))
     return JUMP_INSN;
   if (GET_CODE (x) == SET)
     {
@@ -776,7 +776,7 @@ classify_insn (rtx x)
       if (has_return_p)
 	return JUMP_INSN;
       if (GET_CODE (XVECEXP (x, 0, 0)) == ASM_OPERANDS
-	  && ASM_OPERANDS_LABEL_VEC (XVECEXP (x, 0, 0)))
+	  && ASM_OPERANDS_LABEL_LENGTH (XVECEXP (x, 0, 0)))
 	return JUMP_INSN;
     }
 #ifdef GENERATOR_FILE
diff --git a/gcc/testsuite/gcc.dg/torture/tls/pr104777.c b/gcc/testsuite/gcc.dg/torture/tls/pr104777.c
new file mode 100644
index 00000000000..abaf59731fc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/tls/pr104777.c
@@ -0,0 +1,30 @@
+/* PR rtl-optimization/104777 */
+/* { dg-do compile } */
+/* { dg-require-effective-target tls } */
+ 
+int savestate_r;
+int savestate_ssb;
+extern void abort();
+__thread int  loop;
+void f (void)
+{
+  int savestate_r0_5;
+  int savestate_r1_6;
+
+  __asm__("" : "=m" (savestate_ssb), "=r" (savestate_r));
+  savestate_r0_5 = savestate_r;
+  if (savestate_r0_5 == 0)
+  {
+    __asm__ __volatile__("" :  : "m" (loop));
+    abort ();
+  }
+
+  __asm__("" : "=m" (savestate_ssb), "=r" (savestate_r));
+  savestate_r1_6 = savestate_r;
+  if (savestate_r1_6 != 0)
+    return;
+
+  __asm__ __volatile__("" :  : "m" (loop));
+  abort ();
+
+}


                 reply	other threads:[~2022-06-13 16:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220613162950.27608381BBC9@sourceware.org \
    --to=mpolacek@gcc.gnu.org \
    --cc=gcc-cvs@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).