public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ventana/heads/far-branch-for-gcc11)] return addr will get clobbered in non-leaf
@ 2021-01-04 18:02 Philipp Tomsich
0 siblings, 0 replies; only message in thread
From: Philipp Tomsich @ 2021-01-04 18:02 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:96bed9cb498b8f6d778a8b0598f6b5290849fbf3
commit 96bed9cb498b8f6d778a8b0598f6b5290849fbf3
Author: Philipp Tomsich <philipp.tomsich@vrull.eu>
Date: Sat Jan 2 17:51:22 2021 +0100
return addr will get clobbered in non-leaf
refactor 'should return addr be saved'?
gcc/ChangeLog:
* config/riscv/riscv.c (riscv_save_return_addr_reg_p):
(riscv_save_reg_p):
Diff:
---
gcc/config/riscv/riscv.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 46c6538330e..c88aca8120e 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -3630,6 +3630,30 @@ riscv_far_jump_used_p ()
return cfun->machine->far_jump_used;
}
+/* Return true, if the current function must save the incoming return
+ address. */
+
+static bool
+riscv_save_return_addr_reg_p (void)
+{
+ /* The $ra register is call-clobbered: if this is not a leaf function,
+ save it. */
+ if (!crtl->is_leaf)
+ return true;
+
+ /* We need to save the incoming return address if __builtin_eh_return
+ is being used to set a different return address. */
+ if (crtl->calls_eh_return)
+ return true;
+
+ /* Far jumps/branches use $ra as a temporary to set up the target jump
+ location (clobbering the incoming return address). */
+ if (riscv_far_jump_used_p ())
+ return true;
+
+ return false;
+}
+
/* Return true if the current function must save register REGNO. */
static bool
@@ -3645,10 +3669,7 @@ riscv_save_reg_p (unsigned int regno)
if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
return true;
- if (regno == RETURN_ADDR_REGNUM && crtl->calls_eh_return)
- return true;
-
- if (regno == RETURN_ADDR_REGNUM && riscv_far_jump_used_p ())
+ if (regno == RETURN_ADDR_REGNUM && riscv_save_return_addr_reg_p ())
return true;
/* If this is an interrupt handler, then must save extra registers. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-04 18:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04 18:02 [gcc(refs/vendors/ventana/heads/far-branch-for-gcc11)] return addr will get clobbered in non-leaf Philipp Tomsich
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).