public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] aarch64: Hybrid support for calls to __capability functions
@ 2022-05-06 14:44 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d650e5dfb0bd91bfb6657685c4bf649c6729015e

commit d650e5dfb0bd91bfb6657685c4bf649c6729015e
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Apr 27 14:00:12 2022 +0100

    aarch64: Hybrid support for calls to __capability functions
    
    This patch adds hybrid support for calling functions such as:
    
      void (*__capability foo)(void);

Diff:
---
 gcc/cfgexpand.c                                   |  8 +--
 gcc/config/aarch64/aarch64.c                      |  4 +-
 gcc/testsuite/gcc.target/aarch64/morello/call-1.c | 15 ++++++
 gcc/testsuite/gcc.target/aarch64/morello/call-2.c | 64 +++++++++++++++++++++++
 4 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 305c2d07233..df0cca0e3e4 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -2637,9 +2637,11 @@ expand_call_stmt (gcall *stmt)
   /* If this is not a builtin function, the function type through which the
      call is made may be different from the type of the function.  */
   if (!builtin_p)
-    CALL_EXPR_FN (exp)
-      = fold_convert (build_pointer_type (gimple_call_fntype (stmt)),
-		      CALL_EXPR_FN (exp));
+    {
+      tree type = change_pointer_target_type (TREE_TYPE (CALL_EXPR_FN (exp)),
+					      gimple_call_fntype (stmt));
+      CALL_EXPR_FN (exp) = fold_convert (type, CALL_EXPR_FN (exp));
+    }
 
   TREE_TYPE (exp) = gimple_call_return_type (stmt);
   CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 66db7e14e19..d953278d920 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -10402,7 +10402,7 @@ aarch64_expand_call (rtx result, rtx mem, rtx callee_abi, bool sibcall)
   gcc_assert (MEM_P (mem));
   callee = XEXP (mem, 0);
   mode = GET_MODE (callee);
-  gcc_assert (mode == Pmode);
+  gcc_assert (aarch64_mem_addr_mode_p (mode));
 
   /* Decide if we should generate indirect calls by loading the
      address of the callee into a register before performing
@@ -10421,7 +10421,7 @@ aarch64_expand_call (rtx result, rtx mem, rtx callee_abi, bool sibcall)
   if (sibcall)
     tmp = ret_rtx;
   else
-    tmp = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, LR_REGNUM));
+    tmp = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (mode, LR_REGNUM));
 
   gcc_assert (CONST_INT_P (callee_abi));
   callee_abi = gen_rtx_UNSPEC (DImode, gen_rtvec (1, callee_abi),
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/call-1.c b/gcc/testsuite/gcc.target/aarch64/morello/call-1.c
new file mode 100644
index 00000000000..0c9b33cfd24
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/call-1.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+#if !__CHERI_PURE_CAPABILITY__
+#pragma GCC target "arch=morello"
+#endif
+
+int (*__capability ret)(int);
+int ret_sibcall() { return ret(1); }
+int ret_call() { return ret(2) + 1; }
+
+void (*__capability noret)(int);
+int noret_sibcall() { noret(1); }
+int noret_call() { noret(2); return 1; }
+
+/* { dg-final { scan-assembler-times {\tbl?r\tc[0-9]+} 4 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/call-2.c b/gcc/testsuite/gcc.target/aarch64/morello/call-2.c
new file mode 100644
index 00000000000..783657b56a9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/call-2.c
@@ -0,0 +1,64 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fgimple" } */
+/* { dg-final { check-function-bodies "**" ""  { {-O[23s]} } } } */
+
+int ret(int);
+
+/*
+** ret_sibcall:
+**	mov	w0, #?1
+**	b	ret
+*/
+int __GIMPLE ret_sibcall() {
+  int (*__capability ptr)(int);
+  int res;
+
+  ptr = __CAP_ADDR ret;
+  res = ptr(1);
+  return res;
+}
+
+/*
+** ret_call:
+**	...
+**	bl	ret
+**	...
+*/
+int __GIMPLE ret_call() {
+  int (*__capability ptr)(int);
+  int res;
+  int sum;
+
+  ptr = __CAP_ADDR ret;
+  res = ptr(2);
+  sum = res + 1;
+  return sum;
+}
+
+void noret(int);
+
+/*
+** noret_sibcall:
+**	mov	w0, #?1
+**	b	noret
+*/
+void __GIMPLE noret_sibcall() {
+  void (*__capability ptr)(int);
+
+  ptr = __CAP_ADDR noret;
+  ptr(1);
+}
+
+/*
+** noret_call:
+**	...
+**	bl	noret
+**	...
+*/
+int __GIMPLE noret_call() {
+  void (*__capability ptr)(int);
+
+  ptr = __CAP_ADDR noret;
+  ptr(2);
+  return 1;
+}


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

only message in thread, other threads:[~2022-05-06 14:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:44 [gcc(refs/vendors/ARM/heads/morello)] aarch64: Hybrid support for calls to __capability functions Matthew Malcomson

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