[clang] [analyzer][NFC] Simplify and eliminate redundant map lookups (PR #125272)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 31 11:28:51 PST 2025
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/125272
None
>From 086be8a46407ae1d0e5f8f965858cb6a27b8c5d5 Mon Sep 17 00:00:00 2001
From: Balazs Benics <benicsbalazs at gmail.com>
Date: Fri, 31 Jan 2025 20:26:45 +0100
Subject: [PATCH] [analyzer][NFC] Simplify and eliminate redundant map lookups
---
.../Core/PathSensitive/SMTConstraintManager.h | 7 +------
.../lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp | 7 ++++---
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index 7cfb24e5e649db4..e084a139953062e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -353,12 +353,7 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
addStateConstraints(NewState);
std::optional<bool> res = Solver->check();
- if (!res)
- Cached[hash] = ConditionTruthVal();
- else
- Cached[hash] = ConditionTruthVal(*res);
-
- return Cached[hash];
+ return Cached[hash] = res ? ConditionTruthVal(*res) : ConditionTruthVal();
}
// Cache the result of an SMT query (true, false, unknown). The key is the
diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 5534ef86a7bef68..28898bb3708237a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -227,10 +227,11 @@ void ExprInspectionChecker::analyzerWarnIfReached(const CallExpr *CE,
void ExprInspectionChecker::analyzerNumTimesReached(const CallExpr *CE,
CheckerContext &C) const {
- ++ReachedStats[CE].NumTimesReached;
- if (!ReachedStats[CE].ExampleNode) {
+ ReachedStat &Stat = ReachedStats[CE];
+ ++Stat.NumTimesReached;
+ if (!Stat.ExampleNode) {
// Later, in checkEndAnalysis, we'd throw a report against it.
- ReachedStats[CE].ExampleNode = C.generateNonFatalErrorNode();
+ Stat.ExampleNode = C.generateNonFatalErrorNode();
}
}
More information about the cfe-commits
mailing list