[clang] 1d0f86b - [Sema] Warn unused functions for FMV based on the target attribute (#81302)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 9 13:39:12 PST 2024
Author: Fangrui Song
Date: 2024-02-09T13:39:08-08:00
New Revision: 1d0f86ba80543931d467d6ce3f2ad8cdde514710
URL: https://github.com/llvm/llvm-project/commit/1d0f86ba80543931d467d6ce3f2ad8cdde514710
DIFF: https://github.com/llvm/llvm-project/commit/1d0f86ba80543931d467d6ce3f2ad8cdde514710.diff
LOG: [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")))`.
Added:
clang/test/SemaCXX/attr-target-mv-warn-unused.cpp
Modified:
clang/lib/AST/Decl.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index e281f2d8874a76..5d6bb72a208a1a 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -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();
}
diff --git a/clang/test/SemaCXX/attr-target-mv-warn-unused.cpp b/clang/test/SemaCXX/attr-target-mv-warn-unused.cpp
new file mode 100644
index 00000000000000..1901589ef732fb
--- /dev/null
+++ b/clang/test/SemaCXX/attr-target-mv-warn-unused.cpp
@@ -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(); }
More information about the cfe-commits
mailing list