clang-tools 22.0.0git
CloexecFopenCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/ASTMatchers/ASTMatchFinder.h"
11
12using namespace clang::ast_matchers;
13
14namespace clang::tidy::android {
15
16void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
17 auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter())));
19 Finder, functionDecl(isExternC(), returns(asString("FILE *")),
20 hasName("fopen"), hasParameter(0, CharPointerType),
21 hasParameter(1, CharPointerType)));
22}
23
24void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {
25 insertStringFlag(Result, /*Mode=*/'e', /*ArgPos=*/1);
26}
27
28} // 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
void registerMatchers(ast_matchers::MatchFinder *Finder) override