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