10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 17 namespace linuxkernel {
19 void MustCheckErrsCheck::registerMatchers(MatchFinder *Finder) {
21 functionDecl(hasAnyName(
"ERR_PTR",
"PTR_ERR",
"IS_ERR",
"IS_ERR_OR_NULL",
22 "ERR_CAST",
"PTR_ERR_OR_ZERO"));
23 auto NonCheckingStmts = stmt(anyOf(compoundStmt(), labelStmt()));
25 callExpr(callee(ErrFn), hasParent(NonCheckingStmts)).bind(
"call"),
28 auto ReturnToCheck = returnStmt(hasReturnValue(callExpr(callee(ErrFn))));
29 auto ReturnsErrFn = functionDecl(hasDescendant(ReturnToCheck));
30 Finder->addMatcher(callExpr(callee(ReturnsErrFn), hasParent(NonCheckingStmts))
31 .bind(
"transitive_call"),
35 void MustCheckErrsCheck::check(
const MatchFinder::MatchResult &Result) {
36 const CallExpr *MatchedCallExpr = Result.Nodes.getNodeAs<CallExpr>(
"call");
37 if (MatchedCallExpr) {
38 diag(MatchedCallExpr->getExprLoc(),
"result from function %0 is unused")
39 << MatchedCallExpr->getDirectCallee();
42 const CallExpr *MatchedTransitiveCallExpr =
43 Result.Nodes.getNodeAs<CallExpr>(
"transitive_call");
44 if (MatchedTransitiveCallExpr) {
45 diag(MatchedTransitiveCallExpr->getExprLoc(),
46 "result from function %0 is unused but represents an error value")
47 << MatchedTransitiveCallExpr->getDirectCallee();
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//