]> gcc.gnu.org Git - gcc.git/commitdiff
arm: Avoid emitting bogus CFA adjusts for CMSE nonsecure calls [PR99725]
authorAlex Coplan <alex.coplan@arm.com>
Tue, 11 May 2021 12:11:09 +0000 (13:11 +0100)
committerAlex Coplan <alex.coplan@arm.com>
Tue, 11 May 2021 12:11:09 +0000 (13:11 +0100)
The PR shows us attaching REG_CFA_ADJUST_CFA notes to stack pointer
adjustments emitted in cmse_nonsecure_call_inline_register_clear (when
-march=armv8.1-m.main). However, the stack pointer is not guaranteed to
be the CFA reg. If we're at -O0 or we have -fno-omit-frame-pointer, then
the frame pointer will be used as the CFA reg, and these notes on the sp
adjustments will lead to ICEs in dwarf2out_frame_debug_adjust_cfa.

This patch avoids emitting these notes if the current function has a
frame pointer.

gcc/ChangeLog:

PR target/99725
* config/arm/arm.c (cmse_nonsecure_call_inline_register_clear):
Avoid emitting CFA adjusts on the sp if we have the fp.

gcc/testsuite/ChangeLog:

PR target/99725
* gcc.target/arm/cmse/pr99725.c: New test.

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

index 0371d9818fd83512113ed4f46742979cc016b516..2962071adfd5ec65108d467ed78580addba8faae 100644 (file)
@@ -18774,10 +18774,14 @@ cmse_nonsecure_call_inline_register_clear (void)
                  imm = gen_int_mode (- lazy_store_stack_frame_size, SImode);
                  add_insn = emit_insn (gen_addsi3 (stack_pointer_rtx,
                                                    stack_pointer_rtx, imm));
-                 arm_add_cfa_adjust_cfa_note (add_insn,
-                                              - lazy_store_stack_frame_size,
-                                              stack_pointer_rtx,
-                                              stack_pointer_rtx);
+                 /* If we have the frame pointer, then it will be the
+                    CFA reg.  Otherwise, the stack pointer is the CFA
+                    reg, so we need to emit a CFA adjust.  */
+                 if (!frame_pointer_needed)
+                   arm_add_cfa_adjust_cfa_note (add_insn,
+                                                - lazy_store_stack_frame_size,
+                                                stack_pointer_rtx,
+                                                stack_pointer_rtx);
                  emit_insn (gen_lazy_store_multiple_insn (stack_pointer_rtx));
                }
              /* Save VFP callee-saved registers.  */
@@ -18815,10 +18819,11 @@ cmse_nonsecure_call_inline_register_clear (void)
                  rtx_insn *add_insn =
                    emit_insn (gen_addsi3 (stack_pointer_rtx,
                                           stack_pointer_rtx, imm));
-                 arm_add_cfa_adjust_cfa_note (add_insn,
-                                              lazy_store_stack_frame_size,
-                                              stack_pointer_rtx,
-                                              stack_pointer_rtx);
+                 if (!frame_pointer_needed)
+                   arm_add_cfa_adjust_cfa_note (add_insn,
+                                                lazy_store_stack_frame_size,
+                                                stack_pointer_rtx,
+                                                stack_pointer_rtx);
                }
              /* Restore VFP callee-saved registers.  */
              else
diff --git a/gcc/testsuite/gcc.target/arm/cmse/pr99725.c b/gcc/testsuite/gcc.target/arm/cmse/pr99725.c
new file mode 100644 (file)
index 0000000..284da18
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mcmse -g" } */
+typedef int __attribute__((cmse_nonsecure_call)) (*t)();
+t f;
+void g() { f(); }
This page took 0.106793 seconds and 5 git commands to generate.