1 //===--- CloexecAccept4Check.cpp - clang-tidy------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "CloexecAccept4Check.h"
10 #include "../utils/ASTUtils.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers
;
16 namespace clang::tidy::android
{
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"))));
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()))));
31 void CloexecAccept4Check::check(const MatchFinder::MatchResult
&Result
) {
32 insertMacroFlag(Result
, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3);
35 } // namespace clang::tidy::android