Internals: Add some additional dangling checks. No functional change intended

This commit is contained in:
Wilson Snyder 2025-12-06 18:52:09 -05:00
parent 587f363e03
commit 35a794687b
7 changed files with 11 additions and 11 deletions

View File

@ -303,7 +303,7 @@ class AssertVisitor final : public VNVisitor {
if (AstPExpr* const pexprp = VN_CAST(propp, PExpr)) { if (AstPExpr* const pexprp = VN_CAST(propp, PExpr)) {
AstFork* const forkp = new AstFork{nodep->fileline(), VJoinType::JOIN_NONE}; AstFork* const forkp = new AstFork{nodep->fileline(), VJoinType::JOIN_NONE};
forkp->addForksp(pexprp->bodyp()->unlinkFrBack()); forkp->addForksp(pexprp->bodyp()->unlinkFrBack());
VL_DO_DANGLING(pushDeletep(pexprp), pexprp); VL_DO_DANGLING2(pushDeletep(pexprp), pexprp, propp);
bodyp = forkp; bodyp = forkp;
} else { } else {
bodyp = assertCond(nodep, VN_AS(propp, NodeExpr), passsp, failsp); bodyp = assertCond(nodep, VN_AS(propp, NodeExpr), passsp, failsp);

View File

@ -479,7 +479,7 @@ class CaseVisitor final : public VNVisitor {
condp = irangep->newAndFromInside(cexprp->cloneTreePure(true), condp = irangep->newAndFromInside(cexprp->cloneTreePure(true),
irangep->lhsp()->unlinkFrBack(), irangep->lhsp()->unlinkFrBack(),
irangep->rhsp()->unlinkFrBack()); irangep->rhsp()->unlinkFrBack());
VL_DO_DANGLING(icondp->deleteTree(), icondp); VL_DO_DANGLING2(icondp->deleteTree(), icondp, irangep);
} else if (iconstp && iconstp->num().isFourState() } else if (iconstp && iconstp->num().isFourState()
&& (nodep->casex() || nodep->casez() || nodep->caseInside())) { && (nodep->casex() || nodep->casez() || nodep->caseInside())) {
V3Number nummask{itemp, iconstp->width()}; V3Number nummask{itemp, iconstp->width()};

View File

@ -3648,7 +3648,7 @@ class ConstVisitor final : public VNVisitor {
while (AstNode* const nextp = lastp->nextp()) lastp = nextp; while (AstNode* const nextp = lastp->nextp()) lastp = nextp;
if (AstLoopTest* const testp = VN_CAST(lastp, LoopTest)) { if (AstLoopTest* const testp = VN_CAST(lastp, LoopTest)) {
if (testp->condp()->isZero()) { if (testp->condp()->isZero()) {
VL_DO_DANGLING(pushDeletep(testp->unlinkFrBack()), testp); VL_DO_DANGLING2(pushDeletep(testp->unlinkFrBack()), testp, lastp);
nodep->replaceWith(nodep->stmtsp()->unlinkFrBackWithNext()); nodep->replaceWith(nodep->stmtsp()->unlinkFrBackWithNext());
VL_DO_DANGLING(pushDeletep(nodep), nodep); VL_DO_DANGLING(pushDeletep(nodep), nodep);
return; return;

View File

@ -1229,7 +1229,7 @@ class DelayedVisitor final : public VNVisitor {
// Replace with result // Replace with result
currp->replaceWith(exprp->resultp()->unlinkFrBack()); currp->replaceWith(exprp->resultp()->unlinkFrBack());
// Get rid of the AstExprStmt // 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)) { } else if (AstVarRef* const refp = VN_CAST(currp, VarRef)) {
// Ignore reads (e.g.: '_[*here*] <= _') // Ignore reads (e.g.: '_[*here*] <= _')
if (refp->access().isReadOnly()) return; if (refp->access().isReadOnly()) return;

View File

@ -1870,13 +1870,13 @@ class LinkDotFindVisitor final : public VNVisitor {
for (AstNode *nextp, *argp = loopvarsp->elementsp(); argp; argp = nextp) { for (AstNode *nextp, *argp = loopvarsp->elementsp(); argp; argp = nextp) {
nextp = argp->nextp(); nextp = argp->nextp();
AstVar* argrefp = nullptr; 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 // We use an int type, this might get changed in V3Width when types resolve
argrefp = new AstVar{parserefp->fileline(), VVarType::BLOCKTEMP, argrefp = new AstVar{parserefp->fileline(), VVarType::BLOCKTEMP,
parserefp->name(), argp->findSigned32DType()}; parserefp->name(), argp->findSigned32DType()};
argrefp->lifetime(VLifetime::AUTOMATIC_EXPLICIT); argrefp->lifetime(VLifetime::AUTOMATIC_EXPLICIT);
parserefp->replaceWith(argrefp); parserefp->replaceWith(argrefp);
VL_DO_DANGLING(parserefp->deleteTree(), parserefp); VL_DO_DANGLING2(parserefp->deleteTree(), parserefp, argp);
// Insert argref's name into symbol table // Insert argref's name into symbol table
m_statep->insertSym(m_curSymp, argrefp->name(), argrefp, nullptr); m_statep->insertSym(m_curSymp, argrefp->name(), argrefp, nullptr);
} else if (const auto largrefp = VN_CAST(argp, Var)) { } else if (const auto largrefp = VN_CAST(argp, Var)) {
@ -4646,7 +4646,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
AstNode* addp = pinp; AstNode* addp = pinp;
if (AstArg* const argp = VN_CAST(pinp, Arg)) { if (AstArg* const argp = VN_CAST(pinp, Arg)) {
addp = argp->exprp()->unlinkFrBack(); addp = argp->exprp()->unlinkFrBack();
VL_DO_DANGLING(pushDeletep(pinp), pinp); VL_DO_DANGLING2(pushDeletep(pinp), pinp, argp);
} }
outp = AstNode::addNext(outp, addp); outp = AstNode::addNext(outp, addp);
} }

View File

@ -619,7 +619,7 @@ class LinkParseVisitor final : public VNVisitor {
= new AstSelLoopVars{selp->fileline(), selp->fromp()->unlinkFrBack(), = new AstSelLoopVars{selp->fileline(), selp->fromp()->unlinkFrBack(),
selp->bitp()->unlinkFrBackWithNext()}; selp->bitp()->unlinkFrBackWithNext()};
selp->replaceWith(newp); selp->replaceWith(newp);
VL_DO_DANGLING(selp->deleteTree(), selp); VL_DO_DANGLING2(selp->deleteTree(), selp, bracketp);
} else if (VN_IS(bracketp, SelLoopVars)) { } else if (VN_IS(bracketp, SelLoopVars)) {
// Ok // Ok
} else { } else {
@ -952,7 +952,7 @@ class LinkParseVisitor final : public VNVisitor {
citemp->v3fatalSrc("Incorrect direction"); citemp->v3fatalSrc("Incorrect direction");
} }
} }
VL_DO_DANGLING(pushDeletep(citemp->unlinkFrBack()), citemp); VL_DO_DANGLING2(pushDeletep(citemp->unlinkFrBack()), citemp, itemp);
} }
} }
iterateChildren(nodep); iterateChildren(nodep);

View File

@ -5597,7 +5597,7 @@ class WidthVisitor final : public VNVisitor {
AstNode* const bodyp = nodep->stmtsp(); AstNode* const bodyp = nodep->stmtsp();
userIterateAndNext(bodyp, nullptr); userIterateAndNext(bodyp, nullptr);
if (AstForeach* const loopp = VN_CAST(nodep, Foreach)) { if (AstForeach* const loopp = VN_CAST(nodep, Foreach)) {
VL_DO_DANGLING(V3Begin::convertToWhile(loopp), nodep); VL_DO_DANGLING2(V3Begin::convertToWhile(loopp), loopp, nodep);
return; return;
} }
} }
@ -8945,7 +8945,7 @@ class WidthVisitor final : public VNVisitor {
if (!constp || (noFourState && constp->num().isFourState())) { if (!constp || (noFourState && constp->num().isFourState())) {
nodep->v3error(message); nodep->v3error(message);
nodep->replaceWith(new AstConst{nodep->fileline(), AstConst::Unsized32{}, 1}); nodep->replaceWith(new AstConst{nodep->fileline(), AstConst::Unsized32{}, 1});
VL_DO_DANGLING(pushDeletep(nodep), nodep); VL_DO_DANGLING2(pushDeletep(nodep), nodep, constp);
return; return;
} }
} }