Skip to content

Commit

Permalink
[Sema] Warn unused functions for FMV based on the target attribute (#…
Browse files Browse the repository at this point in the history
…81302)

The spurious -Wunused-function warning issue for `target_version` #80227
also applied to `__attribute__((target(...)))` based FMV. #81167 removed
warnings for all `target`-based FMV. This patch restores the warnings
for `__attribute__((target("default")))`.
  • Loading branch information
MaskRay committed Feb 9, 2024
1 parent 7fd1466 commit 1d0f86b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,11 @@ bool FunctionDecl::isTargetMultiVersion() const {
}

bool FunctionDecl::isTargetMultiVersionDefault() const {
return isMultiVersion() && hasAttr<TargetVersionAttr>() &&
if (!isMultiVersion())
return false;
if (hasAttr<TargetAttr>())
return getAttr<TargetAttr>()->isDefaultVersion();
return hasAttr<TargetVersionAttr>() &&
getAttr<TargetVersionAttr>()->isDefaultVersion();
}

Expand Down
16 changes: 16 additions & 0 deletions clang/test/SemaCXX/attr-target-mv-warn-unused.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -Wunused %s

__attribute__((target("sse3")))
static int not_used_fmv() { return 1; }
__attribute__((target("avx2")))
static int not_used_fmv() { return 2; }
__attribute__((target("default")))
static int not_used_fmv() { return 0; } // expected-warning {{unused function 'not_used_fmv'}}

__attribute__((target("sse3")))
static int definitely_used_fmv() { return 1; }
__attribute__((target("avx2")))
static int definitely_used_fmv() { return 2; }
__attribute__((target("default")))
static int definitely_used_fmv() { return 0; }
int definite_user() { return definitely_used_fmv(); }

0 comments on commit 1d0f86b

Please sign in to comment.