1 //===--- CloexecMemfdCreateCheck.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 //===----------------------------------------------------------------------===//
8 
9 #include "CloexecMemfdCreateCheck.h"
10 
11 using namespace clang::ast_matchers;
12 
13 namespace clang {
14 namespace tidy {
15 namespace android {
16 
registerMatchers(MatchFinder * Finder)17 void CloexecMemfdCreateCheck::registerMatchers(MatchFinder *Finder) {
18   auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
19   registerMatchersImpl(
20       Finder, functionDecl(returns(isInteger()), hasName("memfd_create"),
21                            hasParameter(0, CharPointerType),
22                            hasParameter(1, hasType(isInteger()))));
23 }
24 
check(const MatchFinder::MatchResult & Result)25 void CloexecMemfdCreateCheck::check(const MatchFinder::MatchResult &Result) {
26   insertMacroFlag(Result, "MFD_CLOEXEC", /*ArgPos=*/1);
27 }
28 
29 } // namespace android
30 } // namespace tidy
31 } // namespace clang
32