10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
19 void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
20 auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
21 registerMatchersImpl(Finder,
22 functionDecl(isExternC(), returns(isInteger()),
23 hasAnyName(
"open",
"open64"),
24 hasParameter(0, CharPointerType),
25 hasParameter(1, hasType(isInteger()))));
26 registerMatchersImpl(Finder,
27 functionDecl(isExternC(), returns(isInteger()),
29 hasParameter(0, hasType(isInteger())),
30 hasParameter(1, CharPointerType),
31 hasParameter(2, hasType(isInteger()))));
34 void CloexecOpenCheck::check(
const MatchFinder::MatchResult &Result) {
35 const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
36 assert(FD->param_size() > 1);
37 int ArgPos = (FD->param_size() > 2) ? 2 : 1;
38 insertMacroFlag(Result,
"O_CLOEXEC", ArgPos);