fix leaked node

This commit is contained in:
Yilou Wang 2025-10-11 23:24:14 +02:00
parent 3eebebac2b
commit 36a94a4fc5
1 changed files with 12 additions and 7 deletions

View File

@ -1135,11 +1135,14 @@ class ConstraintExprVisitor final : public VNVisitor {
editSMT(nodep, nodep->fromp(), indexp); editSMT(nodep, nodep->fromp(), indexp);
} }
void visit(AstMemberSel* nodep) override { void visit(AstMemberSel* nodep) override {
if (nodep->varp()->rand().isRandomizable()) { if (nodep->varp()->rand().isRandomizable() && nodep->fromp()) {
// Determine dtype based on node type (VarRef or MemberSel) // Determine dtype based on node type (VarRef or MemberSel)
AstNodeDType* const dtype = VN_IS(nodep->fromp(), VarRef) AstNodeDType* dtype = nullptr;
? VN_AS(nodep->fromp(), VarRef)->dtypep() if (VN_IS(nodep->fromp(), VarRef)) {
: VN_AS(nodep->fromp(), MemberSel)->dtypep(); dtype = VN_AS(nodep->fromp(), VarRef)->dtypep();
} else if (VN_IS(nodep->fromp(), MemberSel)) {
dtype = VN_AS(nodep->fromp(), MemberSel)->dtypep();
}
const AstClassRefDType* const classRefDType = VN_CAST(dtype, ClassRefDType); const AstClassRefDType* const classRefDType = VN_CAST(dtype, ClassRefDType);
if (!classRefDType || !classRefDType->classp()) { if (!classRefDType || !classRefDType->classp()) {
@ -1152,8 +1155,9 @@ class ConstraintExprVisitor final : public VNVisitor {
// Check if constraint is from inside the class (internal) or outside (global) // Check if constraint is from inside the class (internal) or outside (global)
if (nodep->user2p() == refClass) { if (nodep->user2p() == refClass) {
// Constraint is internal to the class // Constraint is internal to the class - unwrap the MemberSel
iterateChildren(nodep); // Process fromp first to ensure proper SMT generation
iterate(nodep->fromp());
nodep->replaceWith(nodep->fromp()->unlinkFrBack()); nodep->replaceWith(nodep->fromp()->unlinkFrBack());
VL_DO_DANGLING(nodep->deleteTree(), nodep); VL_DO_DANGLING(nodep->deleteTree(), nodep);
return; return;
@ -1172,7 +1176,8 @@ class ConstraintExprVisitor final : public VNVisitor {
: (VN_IS(rootNode, MemberSel) ? VN_AS(rootNode, MemberSel)->varp() : (VN_IS(rootNode, MemberSel) ? VN_AS(rootNode, MemberSel)->varp()
: nullptr); : nullptr);
if (constrainedVar && constrainedVar->isGlobalConstrained()) { if (constrainedVar && constrainedVar->isGlobalConstrained()) {
iterateChildren(nodep); // Global constraint - unwrap the MemberSel
iterate(nodep->fromp());
nodep->replaceWith(nodep->fromp()->unlinkFrBack()); nodep->replaceWith(nodep->fromp()->unlinkFrBack());
VL_DO_DANGLING(nodep->deleteTree(), nodep); VL_DO_DANGLING(nodep->deleteTree(), nodep);
return; return;