From 35a794687b5b1f901a097d0131242eec02f393f8 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 6 Dec 2025 18:52:09 -0500 Subject: [PATCH] Internals: Add some additional dangling checks. No functional change intended --- src/V3Assert.cpp | 2 +- src/V3Case.cpp | 2 +- src/V3Const.cpp | 2 +- src/V3Delayed.cpp | 2 +- src/V3LinkDot.cpp | 6 +++--- src/V3LinkParse.cpp | 4 ++-- src/V3Width.cpp | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index c89783dbe..02e06592e 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -303,7 +303,7 @@ class AssertVisitor final : public VNVisitor { if (AstPExpr* const pexprp = VN_CAST(propp, PExpr)) { AstFork* const forkp = new AstFork{nodep->fileline(), VJoinType::JOIN_NONE}; forkp->addForksp(pexprp->bodyp()->unlinkFrBack()); - VL_DO_DANGLING(pushDeletep(pexprp), pexprp); + VL_DO_DANGLING2(pushDeletep(pexprp), pexprp, propp); bodyp = forkp; } else { bodyp = assertCond(nodep, VN_AS(propp, NodeExpr), passsp, failsp); diff --git a/src/V3Case.cpp b/src/V3Case.cpp index 3217a7ec0..eb3956d25 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -479,7 +479,7 @@ class CaseVisitor final : public VNVisitor { condp = irangep->newAndFromInside(cexprp->cloneTreePure(true), irangep->lhsp()->unlinkFrBack(), irangep->rhsp()->unlinkFrBack()); - VL_DO_DANGLING(icondp->deleteTree(), icondp); + VL_DO_DANGLING2(icondp->deleteTree(), icondp, irangep); } else if (iconstp && iconstp->num().isFourState() && (nodep->casex() || nodep->casez() || nodep->caseInside())) { V3Number nummask{itemp, iconstp->width()}; diff --git a/src/V3Const.cpp b/src/V3Const.cpp index a058746d1..843937ccb 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -3648,7 +3648,7 @@ class ConstVisitor final : public VNVisitor { while (AstNode* const nextp = lastp->nextp()) lastp = nextp; if (AstLoopTest* const testp = VN_CAST(lastp, LoopTest)) { if (testp->condp()->isZero()) { - VL_DO_DANGLING(pushDeletep(testp->unlinkFrBack()), testp); + VL_DO_DANGLING2(pushDeletep(testp->unlinkFrBack()), testp, lastp); nodep->replaceWith(nodep->stmtsp()->unlinkFrBackWithNext()); VL_DO_DANGLING(pushDeletep(nodep), nodep); return; diff --git a/src/V3Delayed.cpp b/src/V3Delayed.cpp index 4aedfbfc7..77aa0524d 100644 --- a/src/V3Delayed.cpp +++ b/src/V3Delayed.cpp @@ -1229,7 +1229,7 @@ class DelayedVisitor final : public VNVisitor { // Replace with result currp->replaceWith(exprp->resultp()->unlinkFrBack()); // Get rid of the AstExprStmt - VL_DO_DANGLING(pushDeletep(currp), currp); + VL_DO_DANGLING2(pushDeletep(currp), currp, exprp); } else if (AstVarRef* const refp = VN_CAST(currp, VarRef)) { // Ignore reads (e.g.: '_[*here*] <= _') if (refp->access().isReadOnly()) return; diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 9f2d1f111..aafc18630 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1870,13 +1870,13 @@ class LinkDotFindVisitor final : public VNVisitor { for (AstNode *nextp, *argp = loopvarsp->elementsp(); argp; argp = nextp) { nextp = argp->nextp(); AstVar* argrefp = nullptr; - if (const auto parserefp = VN_CAST(argp, ParseRef)) { + if (AstParseRef* const parserefp = VN_CAST(argp, ParseRef)) { // We use an int type, this might get changed in V3Width when types resolve argrefp = new AstVar{parserefp->fileline(), VVarType::BLOCKTEMP, parserefp->name(), argp->findSigned32DType()}; argrefp->lifetime(VLifetime::AUTOMATIC_EXPLICIT); parserefp->replaceWith(argrefp); - VL_DO_DANGLING(parserefp->deleteTree(), parserefp); + VL_DO_DANGLING2(parserefp->deleteTree(), parserefp, argp); // Insert argref's name into symbol table m_statep->insertSym(m_curSymp, argrefp->name(), argrefp, nullptr); } else if (const auto largrefp = VN_CAST(argp, Var)) { @@ -4646,7 +4646,7 @@ class LinkDotResolveVisitor final : public VNVisitor { AstNode* addp = pinp; if (AstArg* const argp = VN_CAST(pinp, Arg)) { addp = argp->exprp()->unlinkFrBack(); - VL_DO_DANGLING(pushDeletep(pinp), pinp); + VL_DO_DANGLING2(pushDeletep(pinp), pinp, argp); } outp = AstNode::addNext(outp, addp); } diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index 2c3b36a7f..977260230 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -619,7 +619,7 @@ class LinkParseVisitor final : public VNVisitor { = new AstSelLoopVars{selp->fileline(), selp->fromp()->unlinkFrBack(), selp->bitp()->unlinkFrBackWithNext()}; selp->replaceWith(newp); - VL_DO_DANGLING(selp->deleteTree(), selp); + VL_DO_DANGLING2(selp->deleteTree(), selp, bracketp); } else if (VN_IS(bracketp, SelLoopVars)) { // Ok } else { @@ -952,7 +952,7 @@ class LinkParseVisitor final : public VNVisitor { citemp->v3fatalSrc("Incorrect direction"); } } - VL_DO_DANGLING(pushDeletep(citemp->unlinkFrBack()), citemp); + VL_DO_DANGLING2(pushDeletep(citemp->unlinkFrBack()), citemp, itemp); } } iterateChildren(nodep); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index ef2a1c118..b18c13f56 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5597,7 +5597,7 @@ class WidthVisitor final : public VNVisitor { AstNode* const bodyp = nodep->stmtsp(); userIterateAndNext(bodyp, nullptr); if (AstForeach* const loopp = VN_CAST(nodep, Foreach)) { - VL_DO_DANGLING(V3Begin::convertToWhile(loopp), nodep); + VL_DO_DANGLING2(V3Begin::convertToWhile(loopp), loopp, nodep); return; } } @@ -8945,7 +8945,7 @@ class WidthVisitor final : public VNVisitor { if (!constp || (noFourState && constp->num().isFourState())) { nodep->v3error(message); nodep->replaceWith(new AstConst{nodep->fileline(), AstConst::Unsized32{}, 1}); - VL_DO_DANGLING(pushDeletep(nodep), nodep); + VL_DO_DANGLING2(pushDeletep(nodep), nodep, constp); return; } }