-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Merged
MaskRay
merged 1 commit into
main
from
users/MaskRay/spr/sema-warn-unused-functions-for-fmv-based-on-the-target-attribute
Feb 9, 2024
Merged
[Sema] Warn unused functions for FMV based on the target attribute #81302
MaskRay
merged 1 commit into
main
from
users/MaskRay/spr/sema-warn-unused-functions-for-fmv-based-on-the-target-attribute
Feb 9, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.4
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
@llvm/pr-subscribers-clang Author: Fangrui Song (MaskRay) ChangesThe spurious -Wunused-function warning issue for Full diff: https://github.com/llvm/llvm-project/pull/81302.diff 2 Files Affected:
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(); }
|
akyrtzi
approved these changes
Feb 9, 2024
jroelofs
approved these changes
Feb 9, 2024
Thanks! |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The spurious -Wunused-function warning issue for
target_version
#80227also applied to
__attribute__((target(...)))
based FMV. #81167 removedwarnings for all
target
-based FMV. This patch restores the warningsfor
__attribute__((target("default")))
.