1 //===--- CloexecFopenCheck.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 #include "CloexecFopenCheck.h" 10 #include "clang/AST/ASTContext.h" 11 #include "clang/AST/Type.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 14 15 using namespace clang::ast_matchers; 16 17 namespace clang { 18 namespace tidy { 19 namespace android { 20 21 void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) { 22 auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter()))); 23 registerMatchersImpl(Finder, 24 functionDecl(isExternC(), returns(asString("FILE *")), 25 hasName("fopen"), 26 hasParameter(0, CharPointerType), 27 hasParameter(1, CharPointerType))); 28 } 29 30 void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) { 31 insertStringFlag(Result, /*Mode=*/'e', /*ArgPos=*/1); 32 } 33 34 } // namespace android 35 } // namespace tidy 36 } // namespace clang 37