From f39e625888e8d29f3d76da0cf2545f42222732d6 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Wed, 4 Dec 2024 08:44:59 +0100 Subject: [PATCH] Add body to randomize only if expression exists after being processed Signed-off-by: Ryszard Rozak --- src/V3Randomize.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 073cda630a..a06761f1e3 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -884,10 +884,12 @@ class ConstraintExprVisitor final : public VNVisitor { m_taskp = new AstTask{nodep->fileline(), name + "_setup_constraint", m_genp}; nodep->user2p(m_taskp); iterateChildren(nodep); - if (AstConstraint* constrp = VN_CAST(nodep, Constraint)) { - m_taskp->addStmtsp(constrp->itemsp()->unlinkFrBackWithNext()); - } else if (AstWith* withp = VN_CAST(nodep, With)) { - m_taskp->addStmtsp(withp->exprp()->unlinkFrBackWithNext()); + if (AstConstraint* const constrp = VN_CAST(nodep, Constraint)) { + if (constrp->itemsp()) { + m_taskp->addStmtsp(constrp->itemsp()->unlinkFrBackWithNext()); + } + } else if (AstWith* const withp = VN_CAST(nodep, With)) { + if (withp->exprp()) m_taskp->addStmtsp(withp->exprp()->unlinkFrBackWithNext()); } } };