|
|
|||
File indexing completed on 2026-05-10 08:36:19
0001 //===--- SignalHandlerCheck.h - clang-tidy ----------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNALHANDLERCHECK_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNALHANDLERCHECK_H 0011 0012 #include "../ClangTidyCheck.h" 0013 #include "clang/Analysis/CallGraph.h" 0014 #include "llvm/ADT/DepthFirstIterator.h" 0015 #include "llvm/ADT/StringSet.h" 0016 0017 namespace clang::tidy::bugprone { 0018 0019 /// Checker for signal handler functions. 0020 /// 0021 /// For the user-facing documentation see: 0022 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/signal-handler.html 0023 class SignalHandlerCheck : public ClangTidyCheck { 0024 public: 0025 enum class AsyncSafeFunctionSetKind { Minimal, POSIX }; 0026 0027 SignalHandlerCheck(StringRef Name, ClangTidyContext *Context); 0028 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 0029 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override; 0030 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 0031 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 0032 0033 private: 0034 /// Check if a function is allowed as a signal handler. 0035 /// Should test the properties of the function, and check in the code body. 0036 /// Should not check function calls in the code (this part is done by the call 0037 /// graph scan). 0038 /// Bug reports are generated for the whole code body (no stop at the first 0039 /// found issue). For issues that are not in the code body, only one 0040 /// bug report is generated. 0041 /// \param FD The function to check. It may or may not have a definition. 0042 /// \param CallOrRef Location of the call to this function (in another 0043 /// function) or the reference to the function (if it is used as a registered 0044 /// signal handler). This is the location where diagnostics are to be placed. 0045 /// \param ChainReporter A function that adds bug report notes to display the 0046 /// chain of called functions from signal handler registration to the current 0047 /// function. This is called at every generated bug report. 0048 /// The bool parameter is used like \c SkipPathEnd in \c reportHandlerChain . 0049 /// \return Returns true if a diagnostic was emitted for this function. 0050 bool checkFunction(const FunctionDecl *FD, const Expr *CallOrRef, 0051 std::function<void(bool)> ChainReporter); 0052 /// Similar as \c checkFunction but only check for C++14 rules. 0053 bool checkFunctionCPP14(const FunctionDecl *FD, const Expr *CallOrRef, 0054 std::function<void(bool)> ChainReporter); 0055 /// Returns true if a standard library function is considered 0056 /// asynchronous-safe. 0057 bool isStandardFunctionAsyncSafe(const FunctionDecl *FD) const; 0058 /// Add diagnostic notes to show the call chain of functions from a signal 0059 /// handler to a function that is called (directly or indirectly) from it. 0060 /// Also add a note to the place where the signal handler is registered. 0061 /// @param Itr Position during a call graph depth-first iteration. It contains 0062 /// the "path" (call chain) from the signal handler to the actual found 0063 /// function call. 0064 /// @param HandlerRef Reference to the signal handler function where it is 0065 /// registered as signal handler. 0066 /// @param SkipPathEnd If true the last item of the call chain (farthest away 0067 /// from the \c signal call) is omitted from note generation. 0068 void reportHandlerChain(const llvm::df_iterator<clang::CallGraphNode *> &Itr, 0069 const DeclRefExpr *HandlerRef, bool SkipPathEnd); 0070 0071 clang::CallGraph CG; 0072 0073 AsyncSafeFunctionSetKind AsyncSafeFunctionSet; 0074 llvm::StringSet<> ConformingFunctions; 0075 }; 0076 0077 } // namespace clang::tidy::bugprone 0078 0079 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNALHANDLERCHECK_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|