On 6/12/25 11:00 AM, Alfie Richards wrote:
This patch introduces the TARGET_REJECT_FUNCTION_CLONE_VERSION hook
which is used to determine if a target_clones version string parses.
If true is returned, a warning is emitted and from then on the version
is ignored.
This is as specified in the Arm C Language Extension. The purpose of this
is to allow some portability of code using target_clones attributes.
Currently this is only properly implemented for the Aarch64 backend.
For riscv which is the only other backend which uses target_version
semantics a partial implementation is present, where this hook is used
to check parsing, in which errors will be emitted on a failed parse
rather than warnings. A refactor of the riscv parsing logic would be
required to enable this functionality fully.
This fixes PR 118339 where parse failures could cause ICE in Aarch64.
gcc/ChangeLog:
PR target/118339
* target.def: Add reject_target_clone_version hook.
* tree.cc (get_clone_attr_versions): Add filter and location argument.
(get_clone_versions): Add filter argument.
* tree.h (get_clone_attr_versions): Add filter and location argument.
(get_clone_versions): Add filter argument.
* config/aarch64/aarch64.cc (aarch64_reject_target_clone_version):
New function
(TARGET_REJECT_FUNCTION_CLONE_VERSION): New define.
* config/riscv/riscv.cc (riscv_reject_target_clone_version):
New function.
(TARGET_REJECT_FUNCTION_CLONE_VERSION): New define.
* doc/tm.texi: Regenerated.
* doc/tm.texi.in: Add documentation for new hook.
* hooks.h (hook_stringslice_locationt_false): New function.
* hooks.cc (hook_stringslice_locationt_false): New function.
gcc/c-family/ChangeLog:
* c-attribs.cc (handle_target_clones_attribute): Update to emit warnings
for rejected versions.
---
gcc/c-family/c-attribs.cc | 27 ++++++++++++++++++++++-----
gcc/config/aarch64/aarch64.cc | 20 ++++++++++++++++++++
gcc/config/riscv/riscv.cc | 18 ++++++++++++++++++
gcc/doc/tm.texi | 5 +++++
gcc/doc/tm.texi.in | 2 ++
gcc/hooks.cc | 6 ++++++
gcc/hooks.h | 3 +++
gcc/target.def | 8 ++++++++
gcc/tree.cc | 15 ++++++++++++---
gcc/tree.h | 15 +++++++++++----
10 files changed, 107 insertions(+), 12 deletions(-)
+ if (versions.length () == 1 && (TARGET_HAS_FMV_TARGET_ATTRIBUTE
+ || num_defaults == 1))
This probably needs some formatting adjustment. Perhaps:
if (versions.length () == 1
&& (TARGET_HAS_FMV_TARGET_ATTRIBUTE || num_defaults == 1))
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 01fc5538f18..a9571a850f1 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -31516,6 +31516,23 @@ aarch64_expand_fp_spaceship (rtx dest, rtx op0, rtx
op1, rtx hint)
}
}
+bool
+aarch64_reject_target_clone_version (string_slice str,
+ location_t loc ATTRIBUTE_UNUSED)
Needs a function comment.
+bool
+riscv_reject_target_clone_version (string_slice str, location_t loc)
Similarly.
+
+bool
+hook_stringslice_locationt_false (string_slice, location_t)
Similarly if the other default hooks have function comments.
OK with the nits above fixed.
jeff