diff --git a/src/V3Const.cpp b/src/V3Const.cpp index b625bd0b85..2890e8d171 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -716,7 +716,10 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { } // Set width and widthMin precisely resultp->dtypeChgWidth(resultWidth, 1); - for (AstNode* const termp : termps) termp->deleteTree(); + for (AstNode* const termp : termps) { + ConstVisitor::s_containsMemberAccess.erase(termp); + termp->deleteTree(); + } return resultp; } const ResultTerm result = v->getResultTerm(); @@ -792,7 +795,10 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { // Only substitute the result if beneficial as determined by operation count if (visitor.m_ops <= resultOps) { - for (AstNode* const termp : termps) termp->deleteTree(); + for (AstNode* const termp : termps) { + ConstVisitor::s_containsMemberAccess.erase(termp); + termp->deleteTree(); + } return nullptr; } @@ -1044,6 +1050,7 @@ class ConstVisitor final : public VNVisitor { if (!operandsSame(ap, bp)) return false; // Do it cp->unlinkFrBack(); + ConstVisitor::s_containsMemberAccess.erase(andp); VL_DO_DANGLING(andp->unlinkFrBack()->deleteTree(), andp); VL_DANGLING(notp); // Replace whichever branch is now dangling @@ -3768,6 +3775,7 @@ class ConstVisitor final : public VNVisitor { AstNode* mainAcceptEdit(AstNode* nodep) { VIsCached::clearCacheTree(); // Avoid using any stale isPure + s_containsMemberAccess.clear(); // Operate starting at a random place return iterateSubtreeReturnEdits(nodep); }