[clang] [Analyzer][NFC] Remove redundant function call (PR #75076)

Gábor Spaits via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 11 10:35:56 PST 2023


https://github.com/spaits updated https://github.com/llvm/llvm-project/pull/75076

>From f3d7181073996dd94e6d0b7ac403e9a3d97f4e0d Mon Sep 17 00:00:00 2001
From: Gabor Spaits <gaborspaits1 at gmail.com>
Date: Mon, 11 Dec 2023 16:59:16 +0100
Subject: [PATCH 1/3] [Analyzer][NFC] Remove redundant function call

PRValueHandler's handle function is only called from
Tracker's track function. In Tracker::track the
ExprNode parameter passed to PRValueHandler::handle
is already the ExplodedNode for the tracked expression.
We do not need to calculate that again.
---
 .../lib/StaticAnalyzer/Core/BugReporterVisitors.cpp  | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 4a9d130c240ae..4a1607530dbd8 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2565,21 +2565,17 @@ class PRValueHandler final : public ExpressionHandler {
   using ExpressionHandler::ExpressionHandler;
 
   Tracker::Result handle(const Expr *E, const ExplodedNode *InputNode,
-                         const ExplodedNode *ExprNode,
+                         const ExplodedNode *RVNode,
                          TrackingOptions Opts) override {
-    if (!E->isPRValue())
-      return {};
-
-    const ExplodedNode *RVNode = findNodeForExpression(ExprNode, E);
-    if (!RVNode)
+    if (!E->isPRValue() || !RVNode)
       return {};
 
     Tracker::Result CombinedResult;
     Tracker &Parent = getParentTracker();
 
-    const auto track = [&CombinedResult, &Parent, ExprNode,
+    const auto track = [&CombinedResult, &Parent, RVNode,
                         Opts](const Expr *Inner) {
-      CombinedResult.combineWith(Parent.track(Inner, ExprNode, Opts));
+      CombinedResult.combineWith(Parent.track(Inner, RVNode, Opts));
     };
 
     // FIXME: Initializer lists can appear in many different contexts

>From 0f36d7e1947380c39f062840ad75bf7bfd8b0bbd Mon Sep 17 00:00:00 2001
From: Gabor Spaits <gaborspaits1 at gmail.com>
Date: Mon, 11 Dec 2023 19:14:36 +0100
Subject: [PATCH 2/3] Add assertion to check if RVNode node for E

---
 clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 4a1607530dbd8..df2be72531e35 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2567,6 +2567,9 @@ class PRValueHandler final : public ExpressionHandler {
   Tracker::Result handle(const Expr *E, const ExplodedNode *InputNode,
                          const ExplodedNode *RVNode,
                          TrackingOptions Opts) override {
+    assert(RVNode->getStmtForDiagnostics() == E &&
+           "RVNode must be the ExplodedNode for the tracked expression.");
+
     if (!E->isPRValue() || !RVNode)
       return {};
 

>From 10cdc26eeb9925cd11bb85f25509ad1a751c99db Mon Sep 17 00:00:00 2001
From: Gabor Spaits <gaborspaits1 at gmail.com>
Date: Mon, 11 Dec 2023 19:35:39 +0100
Subject: [PATCH 3/3] Move RVNode nullptr check

---
 clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index df2be72531e35..fb8630884d994 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2567,10 +2567,14 @@ class PRValueHandler final : public ExpressionHandler {
   Tracker::Result handle(const Expr *E, const ExplodedNode *InputNode,
                          const ExplodedNode *RVNode,
                          TrackingOptions Opts) override {
+
+    if (!RVNode)
+      return {};
+
     assert(RVNode->getStmtForDiagnostics() == E &&
            "RVNode must be the ExplodedNode for the tracked expression.");
 
-    if (!E->isPRValue() || !RVNode)
+    if (!E->isPRValue())
       return {};
 
     Tracker::Result CombinedResult;



More information about the cfe-commits mailing list