clang-tools 20.0.0git
CloexecAccept4Check.cpp
Go to the documentation of this file.
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
10#include "../utils/ASTUtils.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13
14using namespace clang::ast_matchers;
15
16namespace clang::tidy::android {
17
18void CloexecAccept4Check::registerMatchers(MatchFinder *Finder) {
19 auto SockAddrPointerType =
20 hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr"))));
21 auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t"))));
22
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
31void CloexecAccept4Check::check(const MatchFinder::MatchResult &Result) {
32 insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3);
33}
34
35} // namespace clang::tidy::android
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchersImpl(ast_matchers::MatchFinder *Finder, ast_matchers::internal::Matcher< FunctionDecl > Function)
void insertMacroFlag(const ast_matchers::MatchFinder::MatchResult &Result, StringRef MacroFlag, int ArgPos)
Currently, we have three types of fixes.