]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
arm: Fix ICE with CMSE nonsecure calls on Armv8.1-M [PR100333]
authorAlex Coplan <alex.coplan@arm.com>
Wed, 19 May 2021 14:52:45 +0000 (15:52 +0100)
committerAlex Coplan <alex.coplan@arm.com>
Wed, 19 May 2021 14:52:45 +0000 (15:52 +0100)
As the PR shows, we ICE shortly after expanding nonsecure calls for Armv8.1-M.
For Armv8.1-M, we have TARGET_HAVE_FPCXT_CMSE. As it stands, the expander
(arm.md:nonsecure_call_internal) moves the callee's address to a register (with
copy_to_suggested_reg) only if !TARGET_HAVE_FPCXT_CMSE.

However, looking at the pattern which the insn appears to be intended to
match (thumb2.md:*nonsecure_call_reg_thumb2_fpcxt), it requires the
callee's address to be in a register.

This patch therefore just forces the callee's address into a register in
the expander.

gcc/ChangeLog:

PR target/100333
* config/arm/arm.md (nonsecure_call_internal): Always ensure
callee's address is in a register.

gcc/testsuite/ChangeLog:

PR target/100333
* gcc.target/arm/cmse/pr100333.c: New test.

gcc/config/arm/arm.md
gcc/testsuite/gcc.target/arm/cmse/pr100333.c [new file with mode: 0644]

index 45a471a887a314aaac5d46c9189ebf2174c33f7d..064604808cccb2a9d747e1f3055d757217a08db2 100644 (file)
              (use (match_operand 2 "" ""))
              (clobber (reg:SI LR_REGNUM))])]
   "use_cmse"
-  "
   {
+    rtx addr = XEXP (operands[0], 0);
+    rtx tmp = REG_P (addr) ? addr : force_reg (SImode, addr);
+
     if (!TARGET_HAVE_FPCXT_CMSE)
       {
-       rtx tmp =
-         copy_to_suggested_reg (XEXP (operands[0], 0),
-                                gen_rtx_REG (SImode, R4_REGNUM),
-                                SImode);
-
-       operands[0] = replace_equiv_address (operands[0], tmp);
+       rtx r4 = gen_rtx_REG (SImode, R4_REGNUM);
+       emit_move_insn (r4, tmp);
+       tmp = r4;
       }
-  }")
+
+    if (tmp != addr)
+      operands[0] = replace_equiv_address (operands[0], tmp);
+  }
+)
 
 (define_insn "*call_reg_armv5"
   [(call (mem:SI (match_operand:SI 0 "s_register_operand" "r"))
diff --git a/gcc/testsuite/gcc.target/arm/cmse/pr100333.c b/gcc/testsuite/gcc.target/arm/cmse/pr100333.c
new file mode 100644 (file)
index 0000000..d8e3d80
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mcmse" } */
+typedef void __attribute__((cmse_nonsecure_call)) t(void);
+t g;
+void f() {
+  g();
+}