1 //===--- CloexecSocketCheck.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 "CloexecSocketCheck.h" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 14 using namespace clang::ast_matchers; 15 16 namespace clang { 17 namespace tidy { 18 namespace android { 19 20 void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) { 21 registerMatchersImpl(Finder, 22 functionDecl(isExternC(), returns(isInteger()), 23 hasName("socket"), 24 hasParameter(0, hasType(isInteger())), 25 hasParameter(1, hasType(isInteger())), 26 hasParameter(2, hasType(isInteger())))); 27 } 28 29 void CloexecSocketCheck::check(const MatchFinder::MatchResult &Result) { 30 insertMacroFlag(Result, /*MacroFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1); 31 } 32 33 } // namespace android 34 } // namespace tidy 35 } // namespace clang 36