-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Do not allow unorderable features in [[gnu::target{,_clones}]] #98426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Dan Klishch (DanShaders) ChangesThis partially addresses #98244. Full diff: https://github.com/llvm/llvm-project/pull/98426.diff 5 Files Affected:
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d1c7b9d5ae507..4d0c2cfaee965 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10958,7 +10958,9 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) {
}
if (!TargetInfo.validateCpuSupports(BareFeat) ||
- !TargetInfo.isValidFeatureName(BareFeat)) {
+ !TargetInfo.isValidFeatureName(BareFeat) ||
+ (BareFeat != "default" &&
+ TargetInfo.multiVersionSortPriority(BareFeat) == 0)) {
S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
<< Feature << BareFeat;
return true;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index f2cd46d1e7c93..7e857369c1042 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3138,7 +3138,8 @@ bool Sema::checkTargetClonesAttrString(
} else if (Cur == "default") {
DefaultIsDupe = HasDefault;
HasDefault = true;
- } else if (!Context.getTargetInfo().isValidFeatureName(Cur))
+ } else if (!Context.getTargetInfo().isValidFeatureName(Cur) ||
+ Context.getTargetInfo().multiVersionSortPriority(Cur) == 0)
return Diag(CurLoc, diag::warn_unsupported_target_attribute)
<< Unsupported << None << Cur << TargetClones;
if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe)
diff --git a/clang/test/Sema/attr-target-clones.c b/clang/test/Sema/attr-target-clones.c
index e287fce7699b7..4597ea54d02bf 100644
--- a/clang/test/Sema/attr-target-clones.c
+++ b/clang/test/Sema/attr-target-clones.c
@@ -122,3 +122,6 @@ void good_overload5(int) __attribute__((target_clones("mmx", "sse4.2", "default"
void good_isa_level(int) __attribute__((target_clones("default", "arch=x86-64", "arch=x86-64-v2", "arch=x86-64-v3", "arch=x86-64-v4")));
// expected-warning@+1 {{unsupported CPU 'x86-64-v5' in the 'target_clones' attribute string; 'target_clones' attribute ignored}}
void bad_isa_level(int) __attribute__((target_clones("default", "arch=x86-64-v5")));
+
+// expected-warning@+1 {{unsupported 'sha' in the 'target_clones' attribute string; 'target_clones' attribute ignored}}
+void bad_feature(void) __attribute__((target_clones("default", "sse4.2", "sha")));
diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c
index 8218771275e1b..ddb1d82b02f09 100644
--- a/clang/test/Sema/attr-target-mv.c
+++ b/clang/test/Sema/attr-target-mv.c
@@ -170,3 +170,17 @@ int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge"))
int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload7(void);
int __attribute__((target("arch=sandybridge"))) good_overload7(int);
+
+// expected-error@+2 {{function multiversioning doesn't support feature 'sha'}}
+// expected-note@+2 {{function multiversioning caused by this declaration}}
+int __attribute__((target("sha"))) no_priority1(void);
+int __attribute__((target("default"))) no_priority1(void);
+
+int __attribute__((target("default"))) no_priority2(void);
+// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}}
+int __attribute__((target("sha"))) no_priority2(void);
+
+int __attribute__((target("default"))) no_priority3(void);
+int __attribute__((target("avx2"))) no_priority3(void);
+// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}}
+int __attribute__((target("sha"))) no_priority3(void);
diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c
index 5328f056507a7..65ece3c27d299 100644
--- a/clang/test/Sema/attr-target.c
+++ b/clang/test/Sema/attr-target.c
@@ -33,6 +33,8 @@ void __attribute__((target("x86-64"))) baseline(void) {}
//expected-warning@+1 {{unsupported 'x86-64-v2' in the 'target' attribute string}}
void __attribute__((target("x86-64-v2"))) v2(void) {}
+int __attribute__((target("sha"))) good_target_but_not_for_fmv() { return 5; }
+
#elifdef __aarch64__
int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; }
|
Thanks for the fix! |
a8ddcb1
to
6ac4e25
Compare
Rebased on top of main to hopefully pass github CI (no changes otherwise) |
This partially addresses llvm#98244.
6ac4e25
to
7378d62
Compare
@phoebewang Mind taking a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@DanShaders let me know if you need me to merge it for you. |
I do, thanks! |
This partially addresses #98244.