clang-tools 6.0.0

CloexecOpenCheck.cpp
Go to the documentation of this file.
1 //===--- CloexecOpenCheck.cpp - clang-tidy---------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "CloexecOpenCheck.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13
14 using namespace clang::ast_matchers;
15
16 namespace clang {
17 namespace tidy {
18 namespace android {
19
20 void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
21 auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
22 registerMatchersImpl(Finder,
23 functionDecl(isExternC(), returns(isInteger()),
24 hasAnyName("open", "open64"),
25 hasParameter(0, CharPointerType),
26 hasParameter(1, hasType(isInteger()))));
27 registerMatchersImpl(Finder,
28 functionDecl(isExternC(), returns(isInteger()),
29 hasName("openat"),
30 hasParameter(0, hasType(isInteger())),
31 hasParameter(1, CharPointerType),
32 hasParameter(2, hasType(isInteger()))));
33 }
34
35 void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {
36 const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
37 assert(FD->param_size() > 1);
38 int ArgPos = (FD->param_size() > 2) ? 2 : 1;
39 insertMacroFlag(Result, /*MarcoFlag=*/"O_CLOEXEC", ArgPos);
40 }
41
42 } // namespace android
43 } // namespace tidy
44 } // namespace clang
clang::ast_matchers
Definition: ClangTidyDiagnosticConsumer.h:27
CloexecOpenCheck.h
clang
Definition: AndroidTidyModule.cpp:28