clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
UnsafeFunctionsCheck.h
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
#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
16
namespace
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
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unsafe-functions.html
24
class
UnsafeFunctionsCheck
:
public
ClangTidyCheck
{
25
public
:
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
36
struct
CheckedFunction
{
37
std::string
Name
;
38
matchers::MatchesAnyListedRegexNameMatcher::NameMatcher
Pattern
;
39
std::string
Replacement
;
40
std::string
Reason
;
41
};
42
43
private
:
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
ClangTidyCheck.h
Matchers.h
ClangTidyCheck
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition
ClangTidyDiagnosticConsumer.h:70
clang::tidy::bugprone::UnsafeFunctionsCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Definition
UnsafeFunctionsCheck.cpp:355
clang::tidy::bugprone::UnsafeFunctionsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
UnsafeFunctionsCheck.cpp:266
clang::tidy::bugprone::UnsafeFunctionsCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Definition
UnsafeFunctionsCheck.cpp:190
clang::tidy::bugprone::UnsafeFunctionsCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition
UnsafeFunctionsCheck.cpp:361
clang::tidy::bugprone::UnsafeFunctionsCheck::UnsafeFunctionsCheck
UnsafeFunctionsCheck(StringRef Name, ClangTidyContext *Context)
Definition
UnsafeFunctionsCheck.cpp:180
clang::tidy::bugprone::UnsafeFunctionsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
UnsafeFunctionsCheck.cpp:198
clang::tidy::matchers::MatchesAnyListedRegexNameMatcher::NameMatcher
Definition
clang-tidy/utils/Matchers.h:90
clang::tidy::bugprone
Definition
ArgumentCommentCheck.cpp:19
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition
ClangTidyOptions.h:128
clang::tidy::bugprone::UnsafeFunctionsCheck::CheckedFunction
Definition
UnsafeFunctionsCheck.h:36
clang::tidy::bugprone::UnsafeFunctionsCheck::CheckedFunction::Replacement
std::string Replacement
Definition
UnsafeFunctionsCheck.h:39
clang::tidy::bugprone::UnsafeFunctionsCheck::CheckedFunction::Pattern
matchers::MatchesAnyListedRegexNameMatcher::NameMatcher Pattern
Definition
UnsafeFunctionsCheck.h:38
clang::tidy::bugprone::UnsafeFunctionsCheck::CheckedFunction::Name
std::string Name
Definition
UnsafeFunctionsCheck.h:37
clang::tidy::bugprone::UnsafeFunctionsCheck::CheckedFunction::Reason
std::string Reason
Definition
UnsafeFunctionsCheck.h:40
Generated on
for clang-tools by
1.14.0