From 922282eacfc054ddadbec04825d6573179e66200 Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Thu, 21 Nov 2024 12:26:30 +0800 Subject: [PATCH] [TargetVersion] Only enable on RISC-V and AArch64 (#115991) Address https://github.com/llvm/llvm-project/issues/115000. This patch constrains the target_version feature to work only on RISC-V and AArch64 to prevent crashes in Clang. --------- Co-authored-by: Aaron Ballman --- clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/Basic/Attr.td | 2 +- clang/test/Sema/attr-target-version-unsupported.c | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/attr-target-version-unsupported.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 999c88455b64..a2ff05438c94 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -459,6 +459,8 @@ Attribute Changes in Clang - Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to lifetimebound, this can be used to specify when a reference to a function parameter is captured by another capturing entity ``X``. +- The ``target_version`` attribute is now only supported for AArch64 and RISC-V architectures. + Improvements to Clang's diagnostics ----------------------------------- diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 634253d00325..f1780fa10673 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3297,7 +3297,7 @@ def Target : InheritableAttr { }]; } -def TargetVersion : InheritableAttr { +def TargetVersion : DeclOrTypeAttr, TargetSpecificAttr> { let Spellings = [GCC<"target_version">]; let Args = [StringArgument<"NamesStr">]; let Subjects = SubjectList<[Function], ErrorDiag>; diff --git a/clang/test/Sema/attr-target-version-unsupported.c b/clang/test/Sema/attr-target-version-unsupported.c new file mode 100644 index 000000000000..7cf8172f5272 --- /dev/null +++ b/clang/test/Sema/attr-target-version-unsupported.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s + +//expected-warning@+1 {{unknown attribute 'target_version' ignored}} +int __attribute__((target_version("aes"))) foo(void) { return 3; } -- 2.11.4.GIT