https://gcc.gnu.org/g:00d04311840f95558dd4b87b7fa8d29dd55d5989
commit 00d04311840f95558dd4b87b7fa8d29dd55d5989 Author: Richard Ball <richard.b...@arm.com> Date: Mon Sep 16 14:50:47 2024 +0100 aarch64: Add tests and docs for indirect_return attribute This patch adds a new testcase and docs for the indirect_return attribute. gcc/ChangeLog: * doc/extend.texi: Add AArch64 docs for indirect_return attribute. gcc/testsuite/ChangeLog: * gcc.target/aarch64/indirect_return.c: New test. Diff: --- gcc/doc/extend.texi | 5 +++++ gcc/testsuite/gcc.target/aarch64/indirect_return.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 302c3299ede8..f12af7d2115e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4760,6 +4760,11 @@ Enable or disable calls to out-of-line helpers to implement atomic operations. This corresponds to the behavior of the command-line options @option{-moutline-atomics} and @option{-mno-outline-atomics}. +@cindex @code{indirect_return} function attribute, AArch64 +@item indirect_return +Used to inform the compiler that a function may return via +an indirect return. Adds a BTI J instruction under @option{mbranch-protection=} bti. + @end table The above target attributes can be specified as follows: diff --git a/gcc/testsuite/gcc.target/aarch64/indirect_return.c b/gcc/testsuite/gcc.target/aarch64/indirect_return.c new file mode 100644 index 000000000000..959d2268687d --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/indirect_return.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-mbranch-protection=bti" } */ + +int __attribute((indirect_return)) foo (int a) +{ + return a; +} + +int +func1 (int a, int b) +{ + return foo (a + b); +} + +/* { dg-final { scan-assembler-times "bti j" 1 } } */ \ No newline at end of file