lebedev.ri created this revision. lebedev.ri added reviewers: baloghadamsoftware, JonasToth, gribozavr. lebedev.ri added a project: clang-tools-extra. Herald added a subscriber: rnkovacs. Herald added a project: clang.
D59466 <https://reviews.llvm.org/D59466> wants to analyse the `Stmt`, and `ExceptionEscapeCheck` does not have that as a possible entry point. This simplifies addition of `Stmt` analysis entry point. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D59650 Files: clang-tidy/utils/ExceptionAnalyzer.cpp clang-tidy/utils/ExceptionAnalyzer.h Index: clang-tidy/utils/ExceptionAnalyzer.h =================================================================== --- clang-tidy/utils/ExceptionAnalyzer.h +++ clang-tidy/utils/ExceptionAnalyzer.h @@ -128,7 +128,7 @@ IgnoredExceptions = std::move(ExceptionNames); } - ExceptionInfo analyze(const FunctionDecl *Func); + template <typename T> ExceptionInfo analyze(const T *Node); private: ExceptionInfo @@ -138,10 +138,17 @@ throwsException(const Stmt *St, const ExceptionInfo::Throwables &Caught, llvm::SmallSet<const FunctionDecl *, 32> &CallStack); + template <typename T> + void analyze(const T *Node, ExceptionInfo &ExceptionList); + bool IgnoreBadAlloc = true; llvm::StringSet<> IgnoredExceptions; std::map<const FunctionDecl *, ExceptionInfo> FunctionCache; }; + +extern template ExceptionAnalyzer::ExceptionInfo +ExceptionAnalyzer::analyze<FunctionDecl>(const FunctionDecl *Func); + } // namespace utils } // namespace tidy } // namespace clang Index: clang-tidy/utils/ExceptionAnalyzer.cpp =================================================================== --- clang-tidy/utils/ExceptionAnalyzer.cpp +++ clang-tidy/utils/ExceptionAnalyzer.cpp @@ -204,10 +204,9 @@ return Results; } -ExceptionAnalyzer::ExceptionInfo -ExceptionAnalyzer::analyze(const FunctionDecl *Func) { - ExceptionInfo ExceptionList; - +template <> +void ExceptionAnalyzer::analyze(const FunctionDecl *Func, + ExceptionInfo &ExceptionList) { // Check if the function has already been analyzed and reuse that result. if (FunctionCache.count(Func) == 0) { llvm::SmallSet<const FunctionDecl *, 32> CallStack; @@ -220,6 +219,13 @@ FunctionCache.insert(std::make_pair(Func, ExceptionList)); } else ExceptionList = FunctionCache[Func]; +} + +template <typename T> +ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const T *Node) { + ExceptionInfo ExceptionList; + + analyze<T>(Node, ExceptionList); if (ExceptionList.getBehaviour() == State::NotThrowing || ExceptionList.getBehaviour() == State::Unknown) @@ -231,6 +237,10 @@ return ExceptionList; } + +template ExceptionAnalyzer::ExceptionInfo +ExceptionAnalyzer::analyze<FunctionDecl>(const FunctionDecl *Func); + } // namespace utils } // namespace tidy
Index: clang-tidy/utils/ExceptionAnalyzer.h =================================================================== --- clang-tidy/utils/ExceptionAnalyzer.h +++ clang-tidy/utils/ExceptionAnalyzer.h @@ -128,7 +128,7 @@ IgnoredExceptions = std::move(ExceptionNames); } - ExceptionInfo analyze(const FunctionDecl *Func); + template <typename T> ExceptionInfo analyze(const T *Node); private: ExceptionInfo @@ -138,10 +138,17 @@ throwsException(const Stmt *St, const ExceptionInfo::Throwables &Caught, llvm::SmallSet<const FunctionDecl *, 32> &CallStack); + template <typename T> + void analyze(const T *Node, ExceptionInfo &ExceptionList); + bool IgnoreBadAlloc = true; llvm::StringSet<> IgnoredExceptions; std::map<const FunctionDecl *, ExceptionInfo> FunctionCache; }; + +extern template ExceptionAnalyzer::ExceptionInfo +ExceptionAnalyzer::analyze<FunctionDecl>(const FunctionDecl *Func); + } // namespace utils } // namespace tidy } // namespace clang Index: clang-tidy/utils/ExceptionAnalyzer.cpp =================================================================== --- clang-tidy/utils/ExceptionAnalyzer.cpp +++ clang-tidy/utils/ExceptionAnalyzer.cpp @@ -204,10 +204,9 @@ return Results; } -ExceptionAnalyzer::ExceptionInfo -ExceptionAnalyzer::analyze(const FunctionDecl *Func) { - ExceptionInfo ExceptionList; - +template <> +void ExceptionAnalyzer::analyze(const FunctionDecl *Func, + ExceptionInfo &ExceptionList) { // Check if the function has already been analyzed and reuse that result. if (FunctionCache.count(Func) == 0) { llvm::SmallSet<const FunctionDecl *, 32> CallStack; @@ -220,6 +219,13 @@ FunctionCache.insert(std::make_pair(Func, ExceptionList)); } else ExceptionList = FunctionCache[Func]; +} + +template <typename T> +ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const T *Node) { + ExceptionInfo ExceptionList; + + analyze<T>(Node, ExceptionList); if (ExceptionList.getBehaviour() == State::NotThrowing || ExceptionList.getBehaviour() == State::Unknown) @@ -231,6 +237,10 @@ return ExceptionList; } + +template ExceptionAnalyzer::ExceptionInfo +ExceptionAnalyzer::analyze<FunctionDecl>(const FunctionDecl *Func); + } // namespace utils } // namespace tidy
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits