Skip to content

Commit 1d0f86b

Browse files
authored
[Sema] Warn unused functions for FMV based on the target attribute (#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")))`.
1 parent 7fd1466 commit 1d0f86b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,11 @@ bool FunctionDecl::isTargetMultiVersion() const {
35383538
}
35393539

35403540
bool FunctionDecl::isTargetMultiVersionDefault() const {
3541-
return isMultiVersion() && hasAttr<TargetVersionAttr>() &&
3541+
if (!isMultiVersion())
3542+
return false;
3543+
if (hasAttr<TargetAttr>())
3544+
return getAttr<TargetAttr>()->isDefaultVersion();
3545+
return hasAttr<TargetVersionAttr>() &&
35423546
getAttr<TargetVersionAttr>()->isDefaultVersion();
35433547
}
35443548

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -Wunused %s
2+
3+
__attribute__((target("sse3")))
4+
static int not_used_fmv() { return 1; }
5+
__attribute__((target("avx2")))
6+
static int not_used_fmv() { return 2; }
7+
__attribute__((target("default")))
8+
static int not_used_fmv() { return 0; } // expected-warning {{unused function 'not_used_fmv'}}
9+
10+
__attribute__((target("sse3")))
11+
static int definitely_used_fmv() { return 1; }
12+
__attribute__((target("avx2")))
13+
static int definitely_used_fmv() { return 2; }
14+
__attribute__((target("default")))
15+
static int definitely_used_fmv() { return 0; }
16+
int definite_user() { return definitely_used_fmv(); }

0 commit comments

Comments
 (0)