[clang] 40cb73b - [analyzer] Extract ArrayIndexHandler
Valeriy Savchenko via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 15 01:37:56 PDT 2021
Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 40cb73bd20735051eb8f2d43735097d2ff46f0a7
URL: https://github.com/llvm/llvm-project/commit/40cb73bd20735051eb8f2d43735097d2ff46f0a7
DIFF: https://github.com/llvm/llvm-project/commit/40cb73bd20735051eb8f2d43735097d2ff46f0a7.diff
LOG: [analyzer] Extract ArrayIndexHandler
One interesting problem was discovered here. When we do interrupt
Tracker's track flow, we want to interrupt only it and not all the
other flows recursively.
Differential Revision: https://reviews.llvm.org/D103914
Added:
Modified:
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 29768f79c5dd..23f925e49b15 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2134,6 +2134,23 @@ class NilReceiverHandler final : public ExpressionHandler {
}
};
+class ArrayIndexHandler final : public ExpressionHandler {
+public:
+ using ExpressionHandler::ExpressionHandler;
+
+ Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+ const ExplodedNode *LVNode,
+ TrackingOptions Opts) override {
+ // Track the index if this is an array subscript.
+ if (const auto *Arr = dyn_cast<ArraySubscriptExpr>(Inner))
+ return getParentTracker().track(
+ Arr->getIdx(), LVNode,
+ {Opts.Kind, /*EnableNullFPSuppression*/ false});
+
+ return {};
+ }
+};
+
class DefaultExpressionHandler final : public ExpressionHandler {
public:
using ExpressionHandler::ExpressionHandler;
@@ -2146,12 +2163,6 @@ class DefaultExpressionHandler final : public ExpressionHandler {
PathSensitiveBugReport &Report = getParentTracker().getReport();
Tracker::Result Result;
- // Track the index if this is an array subscript.
- if (const auto *Arr = dyn_cast<ArraySubscriptExpr>(Inner))
- Result.combineWith(getParentTracker().track(
- Arr->getIdx(), LVNode,
- {Opts.Kind, /*EnableNullFPSuppression*/ false}));
-
// See if the expression we're interested refers to a variable.
// If so, we can track both its contents and constraints on its value.
if (ExplodedGraph::isInterestingLValueExpr(Inner)) {
@@ -2320,6 +2331,7 @@ Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
// Default expression handlers.
addLowPriorityHandler<ControlDependencyHandler>();
addLowPriorityHandler<NilReceiverHandler>();
+ addLowPriorityHandler<ArrayIndexHandler>();
addLowPriorityHandler<DefaultExpressionHandler>();
addLowPriorityHandler<PRValueHandler>();
// Default store handlers.
@@ -2340,8 +2352,12 @@ Tracker::Result Tracker::track(const Expr *E, const ExplodedNode *N,
// Iterate through the handlers in the order according to their priorities.
for (ExpressionHandlerPtr &Handler : ExpressionHandlers) {
CombinedResult.combineWith(Handler->handle(Inner, N, LVNode, Opts));
- if (CombinedResult.WasInterrupted)
+ if (CombinedResult.WasInterrupted) {
+ // There is no need to confuse our users here.
+ // We got interrupted, but our users don't need to know about it.
+ CombinedResult.WasInterrupted = false;
break;
+ }
}
return CombinedResult;
More information about the cfe-commits
mailing list