Internals: Fix missing relink() and add assert

This commit is contained in:
Wilson Snyder 2023-03-17 22:27:55 -04:00
parent 798d7346cf
commit 80cbf81b3b
2 changed files with 11 additions and 3 deletions

View File

@ -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;

View File

@ -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