Skip to content

[Sema] Warn unused functions for FMV based on the target attribute #81302

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
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
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(); }