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