[PATCH] D147376: [clang-tidy] Small refactor for ExceptionAnalyzer
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 4 00:25:52 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe588ef8a7a53: [clang-tidy] Small refactor for ExceptionAnalyzer (authored by AMS21, committed by PiotrZSL).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147376/new/
https://reviews.llvm.org/D147376
Files:
clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
@@ -21,11 +21,11 @@
/// custom exception types.
class ExceptionAnalyzer {
public:
- enum class State : std::int8_t {
- Throwing = 0, ///< The function can definitely throw given an AST.
- NotThrowing = 1, ///< This function can not throw, given an AST.
- Unknown = 2, ///< This can happen for extern functions without available
- ///< definition.
+ enum class State {
+ Throwing, ///< The function can definitely throw given an AST.
+ NotThrowing, ///< This function can not throw, given an AST.
+ Unknown, ///< This can happen for extern functions without available
+ ///< definition.
};
/// Bundle the gathered information about an entity like a function regarding
@@ -144,7 +144,7 @@
bool IgnoreBadAlloc = true;
llvm::StringSet<> IgnoredExceptions;
- std::map<const FunctionDecl *, ExceptionInfo> FunctionCache;
+ llvm::DenseMap<const FunctionDecl *, ExceptionInfo> FunctionCache{32u};
};
} // namespace clang::tidy::utils
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -537,7 +537,8 @@
ExceptionInfo ExceptionList;
// Check if the function has already been analyzed and reuse that result.
- if (FunctionCache.count(Func) == 0) {
+ const auto CacheEntry = FunctionCache.find(Func);
+ if (CacheEntry == FunctionCache.end()) {
llvm::SmallSet<const FunctionDecl *, 32> CallStack;
ExceptionList = throwsException(Func, CallStack);
@@ -545,9 +546,9 @@
// because it is best to keep as much information as possible.
// The results here might be relevant to different analysis passes
// with different needs as well.
- FunctionCache.insert(std::make_pair(Func, ExceptionList));
+ FunctionCache.try_emplace(Func, ExceptionList);
} else
- ExceptionList = FunctionCache[Func];
+ ExceptionList = CacheEntry->getSecond();
return ExceptionList;
}
@@ -579,8 +580,7 @@
return analyzeDispatch(Func);
}
-ExceptionAnalyzer::ExceptionInfo
-ExceptionAnalyzer::analyze(const Stmt *Stmt) {
+ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const Stmt *Stmt) {
return analyzeDispatch(Stmt);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147376.510715.patch
Type: text/x-patch
Size: 2608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230404/08aa2a93/attachment.bin>
More information about the cfe-commits
mailing list