clang-tools 20.0.0git
UnsafeFunctionsCheck.h
Go to the documentation of this file.
1//===--- UnsafeFunctionsCheck.h - clang-tidy --------------------*- C++ -*-===//
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#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H
11
12#include "../ClangTidyCheck.h"
13#include "../utils/Matchers.h"
14#include <optional>
15
16namespace clang::tidy::bugprone {
17
18/// Checks for functions that have safer, more secure replacements available, or
19/// are considered deprecated due to design flaws. This check relies heavily on,
20/// but is not exclusive to, the functions from the
21/// Annex K. "Bounds-checking interfaces" of C11.
22///
23/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unsafe-functions.html
25public:
26 UnsafeFunctionsCheck(StringRef Name, ClangTidyContext *Context);
27 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
28
29 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31
32 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
33 Preprocessor *ModuleExpanderPP) override;
34 void onEndOfTranslationUnit() override;
35
37 std::string Name;
39 std::string Replacement;
40 std::string Reason;
41 };
42
43private:
44 const std::vector<CheckedFunction> CustomFunctions;
45
46 // If true, the default set of functions are reported.
47 const bool ReportDefaultFunctions;
48 /// If true, additional functions from widely used API-s (such as POSIX) are
49 /// added to the list of reported functions.
50 const bool ReportMoreUnsafeFunctions;
51
52 Preprocessor *PP = nullptr;
53 /// Whether "Annex K" functions are available and should be
54 /// suggested in diagnostics. This is filled and cached internally.
55 std::optional<bool> IsAnnexKAvailable;
56};
57
58} // namespace clang::tidy::bugprone
59
60#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Checks for functions that have safer, more secure replacements available, or are considered deprecate...
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
llvm::StringMap< ClangTidyValue > OptionMap
matchers::MatchesAnyListedNameMatcher::NameMatcher Pattern