Skip to content

Commit

Permalink
Fix randomize with foreach constraints (verilator#5492)
Browse files Browse the repository at this point in the history
Signed-off-by: Arkadiusz Kozdra <[email protected]>
  • Loading branch information
kozdra authored Sep 26, 2024
1 parent 2a01365 commit 02e7767
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,11 @@ class CaptureVisitor final : public VNVisitor {
const bool varHasAutomaticLifetime = varRefp->varp()->lifetime().isAutomatic();
const bool varIsFieldOfCaller = AstClass::isClassExtendedFrom(callerClassp, varClassp);
const bool varIsParam = varRefp->varp()->isParam();
const bool varIsConstraintIterator
= VN_IS(varRefp->varp()->firstAbovep(), SelLoopVars)
&& VN_IS(varRefp->varp()->firstAbovep()->firstAbovep(), ConstraintForeach);
if (refIsXref) return CaptureMode::CAP_VALUE | CaptureMode::CAP_F_XREF;
if (varIsConstraintIterator) return CaptureMode::CAP_NO;
if (varIsFuncLocal && varHasAutomaticLifetime) return CaptureMode::CAP_VALUE;
if (varIsParam) return CaptureMode::CAP_VALUE;
// Static var in function (will not be inlined, because it's in class)
Expand Down
3 changes: 3 additions & 0 deletions test_regress/t/t_randomize_method_with_scoping.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endclass
localparam int PARAM = 42;
class Cls;
rand int x;
int q[$] = {0};
rand enum {
ONE_Y,
TWO_Y
Expand Down Expand Up @@ -98,6 +99,8 @@ class SubC extends SubB;
if (f.x != 0) $stop;
doit &= f.randomize() with { x == op(local::op(op(local::op(1)))); };
if (f.x != 1) $stop;
doit &= f.randomize() with { foreach (q[i]) x == i; };
if (f.x != 0) $stop;
endfunction
endclass

Expand Down

0 comments on commit 02e7767

Please sign in to comment.