From 2927aebe270633b3c2cfe9701642a503a9a9302f Mon Sep 17 00:00:00 2001 From: Yilou Wang Date: Sun, 1 Mar 2026 21:26:50 +0100 Subject: [PATCH] fix the aggressive return, add a lightweight check --- src/V3Width.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/V3Width.cpp b/src/V3Width.cpp index de290ab6b..c819f3250 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -3088,8 +3088,20 @@ class WidthVisitor final : public VNVisitor { iterateCheck(nodep, "Dist Item", itemp, CONTEXT_DET, FINAL, subDTypep, EXTEND_EXP); } - // Inside a constraint, V3Randomize handles dist lowering with proper weights - if (m_constraintp) return; + // Inside a constraint, V3Randomize handles dist lowering with proper weights, + // but only for simple scalar/range items. Container-type items (queues, arrays) + // must be lowered here via insideItem() which knows how to expand them. + if (m_constraintp) { + bool canLower = true; + for (AstDistItem* ditemp = nodep->itemsp(); ditemp; + ditemp = VN_AS(ditemp->nextp(), DistItem)) { + if (!VN_IS(ditemp->rangep(), Const) && !VN_IS(ditemp->rangep(), InsideRange)) { + canLower = false; + break; + } + } + if (canLower) return; + } // Outside constraint: lower to inside (ignores weights) AstNodeExpr* newp = nullptr;