1 //===--- CloexecAccept4Check.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 "CloexecAccept4Check.h"
10 #include "../utils/ASTUtils.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
registerMatchers(MatchFinder * Finder)20 void CloexecAccept4Check::registerMatchers(MatchFinder *Finder) {
21 auto SockAddrPointerType =
22 hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr"))));
23 auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t"))));
24
25 registerMatchersImpl(Finder,
26 functionDecl(returns(isInteger()), hasName("accept4"),
27 hasParameter(0, hasType(isInteger())),
28 hasParameter(1, SockAddrPointerType),
29 hasParameter(2, SockLenPointerType),
30 hasParameter(3, hasType(isInteger()))));
31 }
32
check(const MatchFinder::MatchResult & Result)33 void CloexecAccept4Check::check(const MatchFinder::MatchResult &Result) {
34 insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3);
35 }
36
37 } // namespace android
38 } // namespace tidy
39 } // namespace clang
40