[clang] [TargetVersion] Only enable on RISC-V and AArch64 (PR #115991)

Piyou Chen via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 22:28:52 PST 2024


https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/115991

>From 28f7a2adc055ec6f30790e1e9535c71241a08e29 Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Tue, 12 Nov 2024 20:56:47 -0800
Subject: [PATCH 1/3] [TargetVersion] Only enable on RISC-V and AArch64

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaDeclAttr.cpp                  | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 509d45c0867590..6170c3c10b00ca 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3282,6 +3282,8 @@ def warn_unsupported_target_attribute
               "attribute string; '%select{target|target_clones|target_version}3' "
               "attribute ignored">,
       InGroup<IgnoredAttributes>;
+def err_target_version_unsupported
+    : Error<"target_version attribute is not supported in this target">;
 def err_attribute_unsupported
     : Error<"%0 attribute is not supported on targets missing %1;"
             " specify an appropriate -march= or -mcpu=">;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d05d326178e1b8..e2eaa00c666fc2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3040,6 +3040,11 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
   enum FirstParam { Unsupported };
   enum SecondParam { None };
   enum ThirdParam { Target, TargetClones, TargetVersion };
+
+  if (!Context.getTargetInfo().getTriple().isRISCV() &&
+      !Context.getTargetInfo().getTriple().isAArch64())
+    return Diag(LiteralLoc, diag::err_target_version_unsupported);
+
   llvm::SmallVector<StringRef, 8> Features;
   if (Context.getTargetInfo().getTriple().isRISCV()) {
     llvm::SmallVector<StringRef, 8> AttrStrs;

>From 5355896434206bce33ff2442189aaff4d6b605ad Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Wed, 13 Nov 2024 22:25:05 -0800
Subject: [PATCH 2/3] Add testcase

---
 clang/test/Sema/attr-target-version-unsupported.c | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 clang/test/Sema/attr-target-version-unsupported.c

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..7a868e4085f20e
--- /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-error at +1 {{target_version attribute is not supported in this target}}
+int __attribute__((target_version("aes"))) foo(void) { return 3; }

>From 659b628a12e05610ff82421dd358292c53940e93 Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Wed, 13 Nov 2024 22:28:30 -0800
Subject: [PATCH 3/3] in this target -> on this target

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td  | 2 +-
 clang/test/Sema/attr-target-version-unsupported.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6170c3c10b00ca..0e3e8f90e52252 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3283,7 +3283,7 @@ def warn_unsupported_target_attribute
               "attribute ignored">,
       InGroup<IgnoredAttributes>;
 def err_target_version_unsupported
-    : Error<"target_version attribute is not supported in this target">;
+    : Error<"target_version attribute is not supported on this target">;
 def err_attribute_unsupported
     : Error<"%0 attribute is not supported on targets missing %1;"
             " specify an appropriate -march= or -mcpu=">;
diff --git a/clang/test/Sema/attr-target-version-unsupported.c b/clang/test/Sema/attr-target-version-unsupported.c
index 7a868e4085f20e..056cbd25bd90d4 100644
--- a/clang/test/Sema/attr-target-version-unsupported.c
+++ b/clang/test/Sema/attr-target-version-unsupported.c
@@ -1,4 +1,4 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown  -fsyntax-only -verify %s
 
-//expected-error at +1 {{target_version attribute is not supported in this target}}
+//expected-error at +1 {{target_version attribute is not supported on this target}}
 int __attribute__((target_version("aes"))) foo(void) { return 3; }



More information about the cfe-commits mailing list