[clang] [TargetVersion] Only enable on RISC-V and AArch64 (PR #115991)
Piyou Chen via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 17 18:14:24 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/6] [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/6] 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/6] 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; }
>From 5f7a3ebe81f2dc6af7d558d012d8d05543fa7115 Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Thu, 14 Nov 2024 22:34:18 -0800
Subject: [PATCH 4/6] Using the TargetSpecificAttr instead of InheritableAttr
---
clang/include/clang/Basic/Attr.td | 2 +-
clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 --
clang/lib/Sema/SemaDeclAttr.cpp | 4 ----
clang/test/Sema/attr-target-version-unsupported.c | 2 +-
4 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index a631e81d40aa68..25566482026b55 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3263,7 +3263,7 @@ def Target : InheritableAttr {
}];
}
-def TargetVersion : InheritableAttr {
+def TargetVersion : DeclOrTypeAttr, 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/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0e3e8f90e52252..509d45c0867590 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3282,8 +3282,6 @@ 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 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/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e2eaa00c666fc2..ebb4beb33df103 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3041,10 +3041,6 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
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;
diff --git a/clang/test/Sema/attr-target-version-unsupported.c b/clang/test/Sema/attr-target-version-unsupported.c
index 056cbd25bd90d4..4eff577fb01952 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 on this target}}
+//expected-warning at +1 {{unknown attribute 'target_version' ignored}}
int __attribute__((target_version("aes"))) foo(void) { return 3; }
>From a92daf63ec9f87383e4ec9a8c37803bc4619a18e Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Thu, 14 Nov 2024 23:25:35 -0800
Subject: [PATCH 5/6] Drop blank line
---
clang/lib/Sema/SemaDeclAttr.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ebb4beb33df103..d05d326178e1b8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3040,7 +3040,6 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
enum FirstParam { Unsupported };
enum SecondParam { None };
enum ThirdParam { Target, TargetClones, TargetVersion };
-
llvm::SmallVector<StringRef, 8> Features;
if (Context.getTargetInfo().getTriple().isRISCV()) {
llvm::SmallVector<StringRef, 8> AttrStrs;
>From 182e79f01f436212d35665516e4808aa1c5296be Mon Sep 17 00:00:00 2001
From: Piyou Chen <gccbg04538 at gmail.com>
Date: Mon, 18 Nov 2024 10:14:14 +0800
Subject: [PATCH 6/6] Update clang/test/Sema/attr-target-version-unsupported.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/attr-target-version-unsupported.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/attr-target-version-unsupported.c b/clang/test/Sema/attr-target-version-unsupported.c
index 4eff577fb01952..7cf8172f5272e6 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
+// 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