[PATCH] D116778: [clang-tidy][clang] Don't trigger unused-parameter warnings on naked functions
Tommaso Bonvicini via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 09:50:02 PST 2022
MuAlphaOmegaEpsilon updated this revision to Diff 398182.
MuAlphaOmegaEpsilon added a comment.
Rebased to more recent main branch, updated comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116778/new/
https://reviews.llvm.org/D116778
Files:
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
clang/lib/Sema/SemaDecl.cpp
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14632,8 +14632,17 @@
Diag(FD->getLocation(), diag::ext_pure_function_definition);
if (!FD->isInvalidDecl()) {
- // Don't diagnose unused parameters of defaulted or deleted functions.
- if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody())
+ bool FDHasNakedAttr{false};
+ if (FD->hasAttrs())
+ for (const clang::Attr *A : FD->getAttrs())
+ if (A->getParsedKind() == Attr::AT_Naked) {
+ FDHasNakedAttr = true;
+ break;
+ }
+ // Don't diagnose unused parameters of defaulted, deleted or naked
+ // functions.
+ if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody() &&
+ !FDHasNakedAttr)
DiagnoseUnusedParameters(FD->parameters());
DiagnoseSizeOfParametersAndReturnValue(FD->parameters(),
FD->getReturnType(), FD);
Index: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -174,6 +174,10 @@
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("function");
if (!Function->hasWrittenPrototype() || Function->isTemplateInstantiation())
return;
+ if (Function->hasAttrs())
+ for (const clang::Attr *A : Function->getAttrs())
+ if (A->getParsedKind() == Attr::AT_Naked)
+ return;
if (const auto *Method = dyn_cast<CXXMethodDecl>(Function))
if (Method->isLambdaStaticInvoker())
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116778.398182.patch
Type: text/x-patch
Size: 1837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220107/ef205511/attachment.bin>
More information about the cfe-commits
mailing list