public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9877] arm: Avoid emitting bogus CFA adjusts for CMSE nonsecure calls [PR99725]
@ 2021-06-01 16:22 Alex Coplan
  0 siblings, 0 replies; only message in thread
From: Alex Coplan @ 2021-06-01 16:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1cbde1725cac9ae53b892449c847f28f977f3a9b

commit r10-9877-g1cbde1725cac9ae53b892449c847f28f977f3a9b
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Tue May 11 13:11:09 2021 +0100

    arm: Avoid emitting bogus CFA adjusts for CMSE nonsecure calls [PR99725]
    
    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.
    
    (cherry picked from commit 2ac1f0eb3887335b7a7e845812956fa436e72a91)

Diff:
---
 gcc/config/arm/arm.c                        | 21 +++++++++++++--------
 gcc/testsuite/gcc.target/arm/cmse/pr99725.c |  5 +++++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index ed2ea53b8f7..8f8386c5770 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -18765,10 +18765,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.  */
@@ -18806,10 +18810,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
index 00000000000..284da184f96
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/cmse/pr99725.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mcmse -g" } */
+typedef int __attribute__((cmse_nonsecure_call)) (*t)();
+t f;
+void g() { f(); }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-01 16:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 16:22 [gcc r10-9877] arm: Avoid emitting bogus CFA adjusts for CMSE nonsecure calls [PR99725] Alex Coplan

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).