[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
Thu Jan 13 14:38:00 PST 2022
MuAlphaOmegaEpsilon updated this revision to Diff 399793.
MuAlphaOmegaEpsilon added a comment.
Update code after review and add tests
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-tools-extra/test/clang-tidy/checkers/misc-unused-parameters-strict.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.c
clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-unused-parameters.c
clang/test/SemaCXX/warn-unused-parameters.cpp
Index: clang/test/SemaCXX/warn-unused-parameters.cpp
===================================================================
--- clang/test/SemaCXX/warn-unused-parameters.cpp
+++ clang/test/SemaCXX/warn-unused-parameters.cpp
@@ -32,3 +32,7 @@
auto l = [&t...]() { return sizeof...(s); };
return l();
}
+
+// Do not warn on naked functions.
+[[gnu::naked]] int nakedFunction(int a, float b, const char* c) { ; }
+__attribute__((naked)) void nakedFunction(int a, int b) { ; }
Index: clang/test/Sema/warn-unused-parameters.c
===================================================================
--- clang/test/Sema/warn-unused-parameters.c
+++ clang/test/Sema/warn-unused-parameters.c
@@ -28,3 +28,5 @@
// CHECK-everything-error: 5 errors generated
// CHECK-everything-no-unused: 5 warnings generated
+// Do not warn on naked functions.
+__attribute__((naked)) void nakedFunction(int a, int b) { ; }
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14632,8 +14632,10 @@
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())
+ // Don't diagnose unused parameters of defaulted, deleted or naked
+ // functions.
+ if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody() &&
+ !FD->hasAttr<NakedAttr>())
DiagnoseUnusedParameters(FD->parameters());
DiagnoseSizeOfParametersAndReturnValue(FD->parameters(),
FD->getReturnType(), FD);
Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
@@ -286,3 +286,7 @@
f([](int I) { return; });
}
} // namespace lambda
+
+// Do not warn on naked functions.
+[[gnu::naked]] int nakedFunction(int a, float b, const char *c) { ; }
+__attribute__((naked)) void nakedFunction(int a, int b) { ; }
Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.c
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.c
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.c
@@ -15,3 +15,5 @@
// ===============
void h(i, c, d) int i; char *c, *d; {} // Don't mess with K&R style
+// Do not warn on naked functions.
+__attribute__((naked)) void nakedFunction(int a, int b) { ; }
Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters-strict.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters-strict.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters-strict.cpp
@@ -22,4 +22,8 @@
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'j' is unused
// CHECK-FIXES: {{^}} F(int /*j*/) : i() {}{{$}}
};
+
+// Do not warn on naked functions.
+[[gnu::naked]] int nakedFunction(int a, float b, const char *c) { ; }
+__attribute__((naked)) void nakedFunction(int a, int b) { ; }
}
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
@@ -31,10 +31,11 @@
} // namespace
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(
- functionDecl(isDefinition(), hasBody(stmt()), hasAnyParameter(decl()))
- .bind("function"),
- this);
+ Finder->addMatcher(functionDecl(isDefinition(), hasBody(stmt()),
+ hasAnyParameter(decl()),
+ unless(hasAttr(attr::Kind::Naked)))
+ .bind("function"),
+ this);
}
template <typename T>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116778.399793.patch
Type: text/x-patch
Size: 4256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220113/8745fad5/attachment-0001.bin>
More information about the cfe-commits
mailing list