clang-tools 20.0.0git
CloexecFopenCheck.cpp
Go to the documentation of this file.
1//===--- CloexecFopenCheck.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 "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
15using namespace clang::ast_matchers;
16
17namespace clang::tidy::android {
18
19void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
20 auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
22 functionDecl(isExternC(), returns(asString("FILE *")),
23 hasName("fopen"),
24 hasParameter(0, CharPointerType),
25 hasParameter(1, CharPointerType)));
26}
27
28void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {
29 insertStringFlag(Result, /*Mode=*/'e', /*ArgPos=*/1);
30}
31
32} // namespace clang::tidy::android
void registerMatchersImpl(ast_matchers::MatchFinder *Finder, ast_matchers::internal::Matcher< FunctionDecl > Function)
void insertStringFlag(const ast_matchers::MatchFinder::MatchResult &Result, const char Mode, const int ArgPos)
Type3 is also to add a flag to the corresponding argument, but this time, the flag is some string and...
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.