[clang] 1639dcb - [analyzer] Extract NilReceiverHandler

Valeriy Savchenko via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 15 01:37:54 PDT 2021


Author: Valeriy Savchenko
Date: 2021-06-15T11:37:36+03:00
New Revision: 1639dcb2798469c4372e50bcb6b4cf36ecffd9ce

URL: https://github.com/llvm/llvm-project/commit/1639dcb2798469c4372e50bcb6b4cf36ecffd9ce
DIFF: https://github.com/llvm/llvm-project/commit/1639dcb2798469c4372e50bcb6b4cf36ecffd9ce.diff

LOG: [analyzer] Extract NilReceiverHandler

Differential Revision: https://reviews.llvm.org/D103902

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 10b674be4972..29768f79c5dd 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2116,24 +2116,35 @@ class ControlDependencyHandler final : public ExpressionHandler {
   }
 };
 
-class DefaultExpressionHandler final : public ExpressionHandler {
+class NilReceiverHandler final : public ExpressionHandler {
 public:
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
                          const ExplodedNode *LVNode,
                          TrackingOptions Opts) override {
-    ProgramStateRef LVState = LVNode->getState();
-    const StackFrameContext *SFC = LVNode->getStackFrame();
-    PathSensitiveBugReport &Report = getParentTracker().getReport();
-    Tracker::Result Result;
-
     // The message send could be nil due to the receiver being nil.
     // At this point in the path, the receiver should be live since we are at
     // the message send expr. If it is nil, start tracking it.
     if (const Expr *Receiver =
             NilReceiverBRVisitor::getNilReceiver(Inner, LVNode))
-      Result.combineWith(getParentTracker().track(Receiver, LVNode, Opts));
+      return getParentTracker().track(Receiver, LVNode, Opts);
+
+    return {};
+  }
+};
+
+class DefaultExpressionHandler final : public ExpressionHandler {
+public:
+  using ExpressionHandler::ExpressionHandler;
+
+  Tracker::Result handle(const Expr *Inner, const ExplodedNode *InputNode,
+                         const ExplodedNode *LVNode,
+                         TrackingOptions Opts) override {
+    ProgramStateRef LVState = LVNode->getState();
+    const StackFrameContext *SFC = LVNode->getStackFrame();
+    PathSensitiveBugReport &Report = getParentTracker().getReport();
+    Tracker::Result Result;
 
     // Track the index if this is an array subscript.
     if (const auto *Arr = dyn_cast<ArraySubscriptExpr>(Inner))
@@ -2308,6 +2319,7 @@ class PRValueHandler final : public ExpressionHandler {
 Tracker::Tracker(PathSensitiveBugReport &Report) : Report(Report) {
   // Default expression handlers.
   addLowPriorityHandler<ControlDependencyHandler>();
+  addLowPriorityHandler<NilReceiverHandler>();
   addLowPriorityHandler<DefaultExpressionHandler>();
   addLowPriorityHandler<PRValueHandler>();
   // Default store handlers.


        


More information about the cfe-commits mailing list