1 //===--- UnsafeFunctionsCheck.h - clang-tidy --------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "../utils/Matchers.h"
16 namespace clang::tidy::bugprone
{
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.
23 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unsafe-functions.html
24 class UnsafeFunctionsCheck
: public ClangTidyCheck
{
26 UnsafeFunctionsCheck(StringRef Name
, ClangTidyContext
*Context
);
27 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
29 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
30 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
32 void registerPPCallbacks(const SourceManager
&SM
, Preprocessor
*PP
,
33 Preprocessor
*ModuleExpanderPP
) override
;
34 void onEndOfTranslationUnit() override
;
36 struct CheckedFunction
{
38 matchers::MatchesAnyListedNameMatcher::NameMatcher Pattern
;
39 std::string Replacement
;
44 const std::vector
<CheckedFunction
> CustomFunctions
;
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
;
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
;
58 } // namespace clang::tidy::bugprone
60 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H