[clang] [analyzer][NFC] Remove leftover PreElideState stash in copy elision (PR #211518)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 23 03:48:03 PDT 2026


https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/211518

computeObjectUnderConstruction stashed the program state into PreElideState "before trying to elide, as it'll get overwritten", but never used it. That comment and stash are fossils of the old prepareForObjectConstruction, which returned and threaded the state (`std::tie(State, V) = ...`); the failure path then reverted it with `State = PreElideState;`.

The refactor to the SVal-returning computeObjectUnderConstruction (State is now passed by value and the state updates moved to updateObjectsUnderConstruction) dropped that revert but left the stash and comment behind. State is never overwritten here anymore, so remove the dead PreElideState and reword the comment to describe only the CallOpts stash, which is still needed (CallOpts is passed by reference and genuinely overwritten by the elision attempt).

Found with a clang-query matcher over clang/lib/StaticAnalyzer.
Assisted-by: claude

>From 9b29c9725ac84b5f844a7d79d01342f6b8d0e8cb Mon Sep 17 00:00:00 2001
From: Balazs Benics <benicsbalazs at gmail.com>
Date: Wed, 22 Jul 2026 15:39:34 +0100
Subject: [PATCH] [analyzer][NFC] Remove leftover PreElideState stash in copy
 elision

computeObjectUnderConstruction stashed the program state into PreElideState
"before trying to elide, as it'll get overwritten", but never used it. That
comment and stash are fossils of the old prepareForObjectConstruction, which
returned and threaded the state (`std::tie(State, V) = ...`); the failure path
then reverted it with `State = PreElideState;`.

The refactor to the SVal-returning computeObjectUnderConstruction (State is now
passed by value and the state updates moved to updateObjectsUnderConstruction)
dropped that revert but left the stash and comment behind. State is never
overwritten here anymore, so remove the dead PreElideState and reword the
comment to describe only the CallOpts stash, which is still needed (CallOpts is
passed by reference and genuinely overwritten by the elision attempt).

Found with a clang-query matcher over clang/lib/StaticAnalyzer.
Assisted-by: claude
---
 clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index e048fc210e608..9c10bcbdc4c0d 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -255,8 +255,8 @@ SVal ExprEngine::computeObjectUnderConstruction(
       // also sets the CallOpts flags for us.
       // If the elided copy/move constructor is not supported, there's still
       // benefit in trying to model the non-elided constructor.
-      // Stash our state before trying to elide, as it'll get overwritten.
-      ProgramStateRef PreElideState = State;
+      // Stash the call options before trying to elide, as they'll get
+      // overwritten.
       EvalCallOptions PreElideCallOpts = CallOpts;
 
       SVal V = computeObjectUnderConstruction(



More information about the cfe-commits mailing list