public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alex Coplan <acoplan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-9877] arm: Avoid emitting bogus CFA adjusts for CMSE nonsecure calls [PR99725]
Date: Tue,  1 Jun 2021 16:22:47 +0000 (GMT)	[thread overview]
Message-ID: <20210601162247.81C773954459@sourceware.org> (raw)

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(); }


                 reply	other threads:[~2021-06-01 16:22 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=20210601162247.81C773954459@sourceware.org \
    --to=acoplan@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).