Skip to content

[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

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11108,7 +11108,8 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) {
}

if (!TargetInfo.validateCpuSupports(BareFeat) ||
!TargetInfo.isValidFeatureName(BareFeat)) {
!TargetInfo.isValidFeatureName(BareFeat) ||
(BareFeat != "default" && TargetInfo.getFMVPriority(BareFeat) == 0)) {
S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
<< Feature << BareFeat;
return true;
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3289,7 +3289,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().getFMVPriority(Cur) == 0)
return Diag(CurLoc, diag::warn_unsupported_target_attribute)
<< Unsupported << None << Cur << TargetClones;
if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe)
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Sema/attr-target-clones.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
14 changes: 14 additions & 0 deletions clang/test/Sema/attr-target-mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions clang/test/Sema/attr-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Loading