Skip to content

Commit 1bcf1d7

Browse files
MaskRayjroelofs
authored andcommitted
[Sema] Warn unused functions for FMV based on the target attribute (llvm#81302)
The spurious -Wunused-function warning issue for `target_version` llvm#80227 also applied to `__attribute__((target(...)))` based FMV. llvm#81167 removed warnings for all `target`-based FMV. This patch restores the warnings for `__attribute__((target("default")))`.
1 parent 0e5ba3a commit 1bcf1d7

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
@@ -3485,7 +3485,11 @@ bool FunctionDecl::isTargetMultiVersion() const {
34853485
}
34863486

34873487
bool FunctionDecl::isTargetMultiVersionDefault() const {
3488-
return isMultiVersion() && hasAttr<TargetVersionAttr>() &&
3488+
if (!isMultiVersion())
3489+
return false;
3490+
if (hasAttr<TargetAttr>())
3491+
return getAttr<TargetAttr>()->isDefaultVersion();
3492+
return hasAttr<TargetVersionAttr>() &&
34893493
getAttr<TargetVersionAttr>()->isDefaultVersion();
34903494
}
34913495

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)