Skip to content
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

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

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Feb 9, 2024

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"))).

Created using spr 1.3.4
@MaskRay MaskRay requested a review from jroelofs February 9, 2024 19:10
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 9, 2024

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)

Changes

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"))).


Full diff: https://github.com/llvm/llvm-project/pull/81302.diff

2 Files Affected:

  • (modified) clang/lib/AST/Decl.cpp (+5-1)
  • (added) clang/test/SemaCXX/attr-target-mv-warn-unused.cpp (+16)
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(); }

@jroelofs
Copy link
Contributor

jroelofs commented Feb 9, 2024

Thanks!

@MaskRay MaskRay merged commit 1d0f86b into main Feb 9, 2024
6 of 7 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/sema-warn-unused-functions-for-fmv-based-on-the-target-attribute branch February 9, 2024 21:39
jroelofs pushed a commit to apple/llvm-project that referenced this pull request Feb 9, 2024
…lvm#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")))`.
jroelofs pushed a commit to apple/llvm-project that referenced this pull request Feb 11, 2024
…lvm#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")))`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants