[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang-tools-extra / clang-tidy / android / CloexecOpenCheck.cpp
blob8804bcb41f8f15f67d195cf3253750785f70e1ab
1 //===--- CloexecOpenCheck.cpp - clang-tidy---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "CloexecOpenCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 using namespace clang::ast_matchers;
15 namespace clang::tidy::android {
17 void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
18 auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
19 registerMatchersImpl(Finder,
20 functionDecl(isExternC(), returns(isInteger()),
21 hasAnyName("open", "open64"),
22 hasParameter(0, CharPointerType),
23 hasParameter(1, hasType(isInteger()))));
24 registerMatchersImpl(Finder,
25 functionDecl(isExternC(), returns(isInteger()),
26 hasName("openat"),
27 hasParameter(0, hasType(isInteger())),
28 hasParameter(1, CharPointerType),
29 hasParameter(2, hasType(isInteger()))));
32 void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {
33 const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr);
34 assert(FD->param_size() > 1);
35 int ArgPos = (FD->param_size() > 2) ? 2 : 1;
36 insertMacroFlag(Result, /*MacroFlag=*/"O_CLOEXEC", ArgPos);
39 } // namespace clang::tidy::android