11 #include "../utils/ASTUtils.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 using namespace clang::ast_matchers;
23 void CloexecSocketCheck::registerMatchers(MatchFinder *
Finder) {
25 callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
27 hasParameter(0, hasType(isInteger())),
28 hasParameter(1, hasType(isInteger())),
29 hasParameter(2, hasType(isInteger())))
35 void CloexecSocketCheck::check(
const MatchFinder::MatchResult &Result) {
36 const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(
"socketFn");
37 const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(
"funcDecl");
38 const Expr *FlagArg = MatchedCall->getArg(1);
39 SourceManager &
SM = *Result.SourceManager;
45 SourceLocation EndLoc =
46 Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
47 Result.Context->getLangOpts());
49 diag(EndLoc,
"%0 should use %1 where possible")
51 << FixItHint::CreateInsertion(EndLoc,
static constexpr const char * SOCK_CLOEXEC
std::unique_ptr< ast_matchers::MatchFinder > Finder
bool exprHasBitFlagWithSpelling(const Expr *Flags, const SourceManager &SM, const LangOptions &LangOpts, StringRef FlagName)
Checks whether a macro flag is present in the given argument.