[clang][sema] Fix -Wunused-function on target_version'd file-scope Fn's (#81167)
We should only warn if the default version is the one that is unused. Fixes: https://github.com/llvm/llvm-project/issues/80227
This commit is contained in:
@@ -2615,6 +2615,10 @@ public:
|
||||
/// the target functionality.
|
||||
bool isTargetMultiVersion() const;
|
||||
|
||||
/// True if this function is the default version of a multiversioned dispatch
|
||||
/// function as a part of the target functionality.
|
||||
bool isTargetMultiVersionDefault() const;
|
||||
|
||||
/// True if this function is a multiversioned dispatch function as a part of
|
||||
/// the target-clones functionality.
|
||||
bool isTargetClonesMultiVersion() const;
|
||||
|
||||
@@ -3537,6 +3537,11 @@ bool FunctionDecl::isTargetMultiVersion() const {
|
||||
(hasAttr<TargetAttr>() || hasAttr<TargetVersionAttr>());
|
||||
}
|
||||
|
||||
bool FunctionDecl::isTargetMultiVersionDefault() const {
|
||||
return isMultiVersion() && hasAttr<TargetVersionAttr>() &&
|
||||
getAttr<TargetVersionAttr>()->isDefaultVersion();
|
||||
}
|
||||
|
||||
bool FunctionDecl::isTargetClonesMultiVersion() const {
|
||||
return isMultiVersion() && hasAttr<TargetClonesAttr>();
|
||||
}
|
||||
|
||||
@@ -1393,7 +1393,8 @@ void Sema::ActOnEndOfTranslationUnit() {
|
||||
Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
|
||||
<< /*function=*/0 << DiagD << DiagRange;
|
||||
}
|
||||
} else {
|
||||
} else if (!FD->isTargetMultiVersion() ||
|
||||
FD->isTargetMultiVersionDefault()) {
|
||||
if (FD->getDescribedFunctionTemplate())
|
||||
Diag(DiagD->getLocation(), diag::warn_unused_template)
|
||||
<< /*function=*/0 << DiagD << DiagRange;
|
||||
|
||||
@@ -236,4 +236,20 @@ constexpr int constexpr4() { return 2; }
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((target_version("fp16")))
|
||||
static int not_used_fmv(void) { return 1; }
|
||||
__attribute__((target_version("fp16fml")))
|
||||
static int not_used_fmv(void) { return 2; }
|
||||
__attribute__((target_version("default")))
|
||||
static int not_used_fmv(void) { return 0; } // expected-warning {{unused function 'not_used_fmv'}}
|
||||
|
||||
|
||||
__attribute__((target_version("fp16")))
|
||||
static int definitely_used_fmv(void) { return 1; }
|
||||
__attribute__((target_version("fp16fml")))
|
||||
static int definitely_used_fmv(void) { return 2; }
|
||||
__attribute__((target_version("default")))
|
||||
static int definitely_used_fmv(void) { return 0; }
|
||||
int definite_user(void) { return definitely_used_fmv(); }
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user