https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/215828

When `ExprEngine::Visit` visits a statement, it usually first invokes the 
`PreStmt` callbacks, then performs the statement-specific visitation logic, 
then finally invokes the `PostStmt` callbacks.

Before this commit, `CXXDeleteExpr` did not follow this regular pattern, 
because it invoked the `PostStmt` callbacks before the statement-specific 
logic. This exceptional logic was introduced in 2020 by commit 
9d69072fb80755a0029a01c74892b4bf03f20f65 and I confirmed with the author of 
that commit that the unusual order is not intentional -- it is just an 
accidental mistake.

This commit ensures that `CXXDeleteExpr` also follows the standard order by 
swapping the `PostStmt` step and the `VisitCXXDeleteExpr()` call.

As no (upstream) checkers use the `PostStmt<CXXDeleteExpr>` callback, this is 
-- in practice -- a non-functional change. (The inconsistency was spotted by 
Gábor Tóthvári in the source code.)

From e385599548f0c3545772549d196683be72991a4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <[email protected]>
Date: Wed, 12 Aug 2026 17:13:44 +0200
Subject: [PATCH] [analyzer] Fix timing of `PostStmt<CXXDeleteExpr>`
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When `ExprEngine::Visit` visits a statement, it usually first invokes
the `PreStmt` callbacks, then performs the statement-specific visitation
logic, then finally invokes the `PostStmt` callbacks.

Before this commit, `CXXDeleteExpr` did not follow this regular pattern,
because it invoked the `PostStmt` callbacks before the
statement-specific logic. This exceptional logic was introduced in 2020
by commit 9d69072fb80755a0029a01c74892b4bf03f20f65 and I confirmed with
the author of that commit that the unusual order is not intentional --
it is just an accidental mistake.

This commit ensures that `CXXDeleteExpr` also follows the standard order
by swapping the `PostStmt` step and the `VisitCXXDeleteExpr()` call.

As no (upstream) checkers use the `PostStmt<CXXDeleteExpr>` callback,
this is -- in practice -- a non-functional change. (The inconsistency
was spotted by Gábor Tóthvári in the source code.)
---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 328ed5b23dd83..dd1088d1aaafb 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2133,12 +2133,12 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode 
*Pred,
       ExplodedNodeSet PreVisit;
       const auto *CDE = cast<CXXDeleteExpr>(S);
       getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
-      ExplodedNodeSet PostVisit;
-      getCheckerManager().runCheckersForPostStmt(PostVisit, PreVisit, S, 
*this);
 
-      for (const auto i : PostVisit)
-        VisitCXXDeleteExpr(CDE, i, Dst);
+      ExplodedNodeSet PostVisit;
+      for (const auto i : PreVisit)
+        VisitCXXDeleteExpr(CDE, i, PostVisit);
 
+      getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this);
       break;
     }
       // FIXME: ChooseExpr is really a constant.  We need to fix

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to