1 //===--- CloexecAccept4Check.cpp - clang-tidy------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "CloexecAccept4Check.h" 11 #include "../utils/ASTUtils.h" 12 #include "clang/AST/ASTContext.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.h" 14 15 using namespace clang::ast_matchers; 16 17 namespace clang { 18 namespace tidy { 19 namespace android { 20 21 void CloexecAccept4Check::registerMatchers(MatchFinder *Finder) { 22 auto SockAddrPointerType = 23 hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr")))); 24 auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t")))); 25 26 registerMatchersImpl(Finder, 27 functionDecl(returns(isInteger()), hasName("accept4"), 28 hasParameter(0, hasType(isInteger())), 29 hasParameter(1, SockAddrPointerType), 30 hasParameter(2, SockLenPointerType), 31 hasParameter(3, hasType(isInteger())))); 32 } 33 34 void CloexecAccept4Check::check(const MatchFinder::MatchResult &Result) { 35 insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3); 36 } 37 38 } // namespace android 39 } // namespace tidy 40 } // namespace clang 41