From 485e32a56ea5b43d56bd6024330130b1b73fcd24 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Mon, 26 Jan 2026 14:54:56 +0100 Subject: [PATCH] Save copies before next cloneTree Signed-off-by: Ryszard Rozak --- src/V3Force.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/V3Force.cpp b/src/V3Force.cpp index 0176a05be..01e3b2cc8 100644 --- a/src/V3Force.cpp +++ b/src/V3Force.cpp @@ -102,15 +102,18 @@ public: AstVarRef* const enRefp = new AstVarRef{flp, m_enVscp, VAccess::WRITE}; AstNodeStmt* const enInitStmtsp = rdUpdateStmtsp->cloneTree(true); + for (int i = 0; i < assigns.size(); i++) { + // Save copies, because clonep() works only after the last cloneTree + assigns[i] = assigns[i]->clonep(); + } for (AstAssign* const assignp : assigns) { - AstAssign* const assignClonep = assignp->clonep(); AstVarRef* const lhsVarRefp - = VN_AS(AstNodeVarRef::varRefLValueRecurse(assignClonep->lhsp()), VarRef); + = VN_AS(AstNodeVarRef::varRefLValueRecurse(assignp->lhsp()), VarRef); lhsVarRefp->replaceWith(enRefp->cloneTree(false)); lhsVarRefp->deleteTree(); - assignClonep->rhsp()->unlinkFrBack()->deleteTree(); - V3Number zero{m_enVscp, assignClonep->lhsp()->dtypep()->width()}; - assignClonep->rhsp(new AstConst{flp, zero}); + assignp->rhsp()->unlinkFrBack()->deleteTree(); + V3Number zero{m_enVscp, assignp->lhsp()->dtypep()->width()}; + assignp->rhsp(new AstConst{flp, zero}); } activeInitp->addStmtsp(new AstInitial{flp, enInitStmtsp}); { // Add the combinational override