[clang] [Sema] Warn unused functions for FMV based on the target attribute (PR #81302)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 9 11:10:47 PST 2024
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/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")))`.
>From 77fac857f70202a5da2cab24b1159dea3911ec6c Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 9 Feb 2024 11:10:39 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
clang/lib/AST/Decl.cpp | 6 +++++-
.../test/SemaCXX/attr-target-mv-warn-unused.cpp | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 clang/test/SemaCXX/attr-target-mv-warn-unused.cpp
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index e281f2d8874a7..5d6bb72a208a1 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 0000000000000..1901589ef732f
--- /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