[PATCH] D116778: [clang-tidy][clang] Don't trigger unused-parameter warnings on naked functions

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 11 04:32:09 PST 2022


aaron.ballman added a comment.

Thanks for the fix! Can you be sure to add test coverage for both clang-tidy and Clang to demonstrate the behavior change?



================
Comment at: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp:35
   Finder->addMatcher(
       functionDecl(isDefinition(), hasBody(stmt()), hasAnyParameter(decl()))
           .bind("function"),
----------------
Something along these lines should work instead (you'll have to reformat though).


================
Comment at: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp:177-180
+  if (Function->hasAttrs())
+    for (const clang::Attr *A : Function->getAttrs())
+      if (A->getParsedKind() == Attr::AT_Naked)
+        return;
----------------
I think this should be done using matchers instead of from `check()` if possible so that we get better memoization. See comment above.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:14635-14645
+        bool FDHasNakedAttr{false};
+        if (FD->hasAttrs())
+          for (const clang::Attr *A : FD->getAttrs())
+            if (A->getParsedKind() == Attr::AT_Naked) {
+              FDHasNakedAttr = true;
+              break;
+            }
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116778/new/

https://reviews.llvm.org/D116778



More information about the cfe-commits mailing list