Hi All,
This is a fix for preserve_none to make it fall back to AAPCS when there are
variadic arguments.
This aligns it with the ABI clang uses and defacto defines.
Reg tested and bootstrapped for aarch64-linux-gnu.
Okay for master and later backbort to GCC 16?
KR,
Alfie
-- >8 --
PR target/125838
gcc/ChangeLog:
* config/aarch64/aarch64.cc (aarch64_fntype_abi): Fall back to
AAPCS for preserve_none variadic calls.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/preserve_none_5.c: Update to use AAPCS.
---
gcc/config/aarch64/aarch64.cc | 4 +-
.../gcc.target/aarch64/preserve_none_5.c | 64 ++++++++++++-------
2 files changed, 43 insertions(+), 25 deletions(-)
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 42e56512c61..b6c464ebc9b 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -2591,7 +2591,9 @@ aarch64_fntype_abi (const_tree fntype)
if (lookup_attribute ("aarch64_vector_pcs", TYPE_ATTRIBUTES (fntype)))
return aarch64_simd_abi ();
- if (lookup_attribute ("preserve_none", TYPE_ATTRIBUTES (fntype)))
+ /* Fall back to AAPCS for variadic functions. */
+ if (lookup_attribute ("preserve_none", TYPE_ATTRIBUTES (fntype))
+ && !stdarg_p (fntype))
return aarch64_preserve_none_abi ();
if (aarch64_returns_value_in_sve_regs_p (fntype)
diff --git a/gcc/testsuite/gcc.target/aarch64/preserve_none_5.c
b/gcc/testsuite/gcc.target/aarch64/preserve_none_5.c
index d11bf10a898..80bd949a893 100644
--- a/gcc/testsuite/gcc.target/aarch64/preserve_none_5.c
+++ b/gcc/testsuite/gcc.target/aarch64/preserve_none_5.c
@@ -6,35 +6,51 @@
#include <stdarg.h>
int foo [[gnu::preserve_none]] (...);
-/* Check the pcs argument order is correct. Should be x20-28, x0-7, x10-14,
x9, x15 and that the return arg is x0 */
+/* Check preserve_none falls back to AAPCS for variadic functions. */
/*
** bar:
** ...
-** mov w15, 23
-** mov w9, 22
-** mov w14, 21
-** mov w13, 20
-** mov w12, 19
-** mov w11, 18
-** mov w10, 17
-** mov w7, 16
-** mov w6, 15
-** mov w5, 14
-** mov w4, 13
-** mov w3, 12
-** mov w2, 11
-** mov w1, 10
+** mov w0, 23
+** mov w7, 7
+** mov w6, 6
+** mov w5, 5
+** mov w4, 4
+** mov w3, 3
+** mov w2, 2
+** mov w1, 1
+** str w0, \[sp, 120\]
+** mov w0, 22
+** str w0, \[sp, 112\]
+** mov w0, 21
+** str w0, \[sp, 104\]
+** mov w0, 20
+** str w0, \[sp, 96\]
+** mov w0, 19
+** str w0, \[sp, 88\]
+** mov w0, 18
+** str w0, \[sp, 80\]
+** mov w0, 17
+** str w0, \[sp, 72\]
+** mov w0, 16
+** str w0, \[sp, 64\]
+** mov w0, 15
+** str w0, \[sp, 56\]
+** mov w0, 14
+** str w0, \[sp, 48\]
+** mov w0, 13
+** str w0, \[sp, 40\]
+** mov w0, 12
+** str w0, \[sp, 32\]
+** mov w0, 11
+** str w0, \[sp, 24\]
+** mov w0, 10
+** str w0, \[sp, 16\]
** mov w0, 9
-** mov w28, 8
-** mov w27, 7
-** mov w26, 6
-** mov w25, 5
-** mov w24, 4
-** mov w23, 3
-** mov w22, 2
-** mov w21, 1
-** mov w20, 0
+** str w0, \[sp, 8\]
+** mov w0, 8
+** str w0, \[sp\]
+** mov w0, 0
** bl foo
** add w0, w0, 1
** ...
--
2.34.1
--
Alfie Richards