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 <optional>
14
15namespace clang::tidy::bugprone {
16
17/// Checks for functions that have safer, more secure replacements available, or
18/// are considered deprecated due to design flaws. This check relies heavily on,
19/// but is not exclusive to, the functions from the
20/// Annex K. "Bounds-checking interfaces" of C11.
21///
22/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unsafe-functions.html
23class UnsafeFunctionsCheck : public ClangTidyCheck {
24public:
25 UnsafeFunctionsCheck(StringRef Name, ClangTidyContext *Context);
26 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
27
28 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30
31 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
32 Preprocessor *ModuleExpanderPP) override;
33 void onEndOfTranslationUnit() override;
34
35private:
36 /// If true, additional functions from widely used API-s (such as POSIX) are
37 /// added to the list of reported functions.
38 const bool ReportMoreUnsafeFunctions;
39
40 Preprocessor *PP = nullptr;
41 /// Whether "Annex K" functions are available and should be
42 /// suggested in diagnostics. This is filled and cached internally.
43 std::optional<bool> IsAnnexKAvailable;
44};
45
46} // namespace clang::tidy::bugprone
47
48#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNSAFEFUNCTIONSCHECK_H
49

source code of clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h