MuAlphaOmegaEpsilon created this revision. MuAlphaOmegaEpsilon added a reviewer: aaron.ballman. Herald added subscribers: carlosgalvezp, xazax.hun. MuAlphaOmegaEpsilon requested review of this revision. Herald added projects: clang, clang-tools-extra. Herald added a subscriber: cfe-commits.
This commit checks if a function is marked with the naked attribute and, if it is, will silence the emission of any unused-parameter warning. Inside a naked function only the usage of basic ASM instructions is expected. In this context the parameters can actually be used by fetching them according to the underlying ABI. Since parameters might be used through ASM instructions, the linter and the compiler will have a hard time understanding if one of those is unused or not. Usage of the naked attribute implies the user taking full responsibility in the handling of prologue and epilogue of the function, therefore no unused-parameter warning should ever be triggered whenever a function is marked naked. Repository: rG LLVM Github Monorepo 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,16 @@ Diag(FD->getLocation(), diag::ext_pure_function_definition); if (!FD->isInvalidDecl()) { + 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 or deleted functions. - if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody()) + 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;
Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -14632,8 +14632,16 @@ Diag(FD->getLocation(), diag::ext_pure_function_definition); if (!FD->isInvalidDecl()) { + 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 or deleted functions. - if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody()) + 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits