vsavchenko updated this revision to Diff 351113. vsavchenko added a comment.
Rebase Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D103914/new/ https://reviews.llvm.org/D103914 Files: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -2136,6 +2136,23 @@ } }; +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; @@ -2148,12 +2165,6 @@ 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)) { @@ -2322,6 +2333,7 @@ // Default expression handlers. addLowPriorityHandler<ControlDependencyHandler>(); addLowPriorityHandler<NilReceiverHandler>(); + addLowPriorityHandler<ArrayIndexHandler>(); addLowPriorityHandler<DefaultExpressionHandler>(); addLowPriorityHandler<RValueHandler>(); // Default store handlers. @@ -2342,8 +2354,12 @@ // 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;
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -2136,6 +2136,23 @@ } }; +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; @@ -2148,12 +2165,6 @@ 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)) { @@ -2322,6 +2333,7 @@ // Default expression handlers. addLowPriorityHandler<ControlDependencyHandler>(); addLowPriorityHandler<NilReceiverHandler>(); + addLowPriorityHandler<ArrayIndexHandler>(); addLowPriorityHandler<DefaultExpressionHandler>(); addLowPriorityHandler<RValueHandler>(); // Default store handlers. @@ -2342,8 +2354,12 @@ // 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits