[clang] 7d8d51e - Recommit "[TargetVersion] Only enable on RISC-V and AArch64" (#117110)" (#117128)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 25 01:10:54 PST 2024


Author: Piyou Chen
Date: 2024-11-25T17:10:50+08:00
New Revision: 7d8d51ed3409cae96fb975281deca2babf4f9994

URL: https://github.com/llvm/llvm-project/commit/7d8d51ed3409cae96fb975281deca2babf4f9994
DIFF: https://github.com/llvm/llvm-project/commit/7d8d51ed3409cae96fb975281deca2babf4f9994.diff

LOG: Recommit "[TargetVersion] Only enable on RISC-V and AArch64" (#117110)" (#117128)

Remain InheritableAttr to avoid the warning `TypePrinter.cpp:1953:10:
warning: enumeration value ‘TargetVersion’ not handled in switch`

origin messenge

[TargetVersion] Only enable on RISC-V and AArch64 (#115991) Address
#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 <aaron at aaronballman.com>

Added: 
    clang/test/Sema/attr-target-version-unsupported.c

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/Basic/Attr.td

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 654204557ad913..b9986434d09d24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -471,6 +471,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 634253d0032560..14009826f2c550 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 : InheritableAttr, TargetSpecificAttr<TargetArch<!listconcat(TargetAArch64.Arches, TargetRISCV.Arches)>> {
   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 00000000000000..7cf8172f5272e6
--- /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 at +1 {{unknown attribute 'target_version' ignored}}
+int __attribute__((target_version("aes"))) foo(void) { return 3; }


        


More information about the cfe-commits mailing list