From 80cbf81b3b394d547a0e85a9e1e5bb592f9cb6b5 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 17 Mar 2023 22:27:55 -0400 Subject: [PATCH] Internals: Fix missing relink() and add assert --- src/V3Ast.h | 8 +++++++- src/V3Clock.cpp | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index cee54c5b8..cae837a51 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1440,6 +1440,13 @@ protected: public: VNRelinker() = default; + ~VNRelinker() { + // Relink is needed so m_iterpp's get restored, e.g. can't have: + // ->unlinkFrBack(relinker); + // if (only_sometimes) relinker.relink(newp); + UDEBUGONLY( + UASSERT_STATIC(!m_backp, "Active linker must be relink()ed before destruction");); + } inline void relink(AstNode* newp); AstNode* oldp() const { return m_oldp; } void dump(std::ostream& str = std::cout) const; @@ -1645,7 +1652,6 @@ public: bool brokeExistsAbove() const { return brokeExists() && (m_brokenState >> 7); } bool brokeExistsBelow() const { return brokeExists() && !(m_brokenState >> 7); } // Note: brokeExistsBelow is not quite precise, as it is true for sibling nodes as well - bool brokeIterpp() const { return !!m_iterpp; } // CONSTRUCTORS virtual ~AstNode() = default; diff --git a/src/V3Clock.cpp b/src/V3Clock.cpp index f2a537555..1a7be8041 100644 --- a/src/V3Clock.cpp +++ b/src/V3Clock.cpp @@ -146,17 +146,19 @@ private: UASSERT_OBJ(nodep->hasClocked(), nodep, "Should have been converted by V3Sched"); UASSERT_OBJ(nodep->stmtsp(), nodep, "Should not have been created if empty"); - VNRelinker relinker; - nodep->unlinkFrBack(&relinker); AstNode* const stmtsp = nodep->stmtsp()->unlinkFrBackWithNext(); // Create 'if' statement, if needed if (!m_lastSenp || !nodep->sensesp()->sameTree(m_lastSenp)) { + VNRelinker relinker; + nodep->unlinkFrBack(&relinker); clearLastSen(); m_lastSenp = nodep->sensesp(); // Make a new if statement m_lastIfp = makeActiveIf(m_lastSenp); relinker.relink(m_lastIfp); + } else { + nodep->unlinkFrBack(); } // Move statements to if