[PATCH] D59650: [NFC] ExceptionEscapeCheck: small refactoring

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 21 09:27:39 PDT 2019


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
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59650.191717.patch
Type: text/x-patch
Size: 2330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190321/0f5bd37f/attachment.bin>


More information about the cfe-commits mailing list