From 1523e55d77df2b6df47e73434d851e139893bc24 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Fri, 22 Nov 2024 09:50:45 +0100 Subject: [PATCH] Fix case with with clause Signed-off-by: Ryszard Rozak --- src/V3Randomize.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 14a5df3c40..fa566ee09b 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -443,7 +443,11 @@ class RandomizeMarkVisitor final : public VNVisitor { void visit(AstMemberSel* nodep) override { if (!m_constraintExprGenp) return; iterateChildrenConst(nodep); - nodep->user1(nodep->fromp()->user1() && nodep->varp()->rand().isRandomizable()); + // Member select are randomized when both object and member are marked as rand. + // Variable references in with clause are converted to member selects and their from() is + // of type AstLambdaArgRef. They are randomized too. + bool randObject = nodep->fromp()->user1() || VN_IS(nodep->fromp(), LambdaArgRef); + nodep->user1(randObject && nodep->varp()->rand().isRandomizable()); } void visit(AstNodeModule* nodep) override { VL_RESTORER(m_modp);