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

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang-tools-extra/clang-tidy/android/CloexecAccept4Check.cpp