Cover dist dedup arms and drop unreachable chain guard

This commit is contained in:
Yilou Wang 2026-07-09 09:36:35 +02:00
parent c99e17065a
commit 0e09102fb6
2 changed files with 55 additions and 1 deletions

View File

@ -4566,7 +4566,6 @@ class RandomizeVisitor final : public VNVisitor {
// frozen variable requires only membership, not a freshly drawn bucket. // frozen variable requires only membership, not a freshly drawn bucket.
AstNode* gateFrozenDist(AstNode* chainp, AstDist* distp, AstNode* gateFrozenDist(AstNode* chainp, AstDist* distp,
const std::vector<DistBucket>& buckets, AstVar* randModeVarp) { const std::vector<DistBucket>& buckets, AstVar* randModeVarp) {
if (!chainp) return chainp;
FileLine* const fl = distp->fileline(); FileLine* const fl = distp->fileline();
AstNodeExpr* gatep = nullptr; AstNodeExpr* gatep = nullptr;
std::unordered_set<const AstVar*> gatedVars; std::unordered_set<const AstVar*> gatedVars;

View File

@ -82,6 +82,19 @@ class MultiVar;
constraint c {(x + y) dist {10 := 9, 1000 := 1};} constraint c {(x + y) dist {10 := 9, 1000 := 1};}
endclass endclass
class DupVar;
rand uint x;
constraint c {(x + x) dist {10 := 9, 20 := 1};}
endclass
class DupMember;
rand Sub s;
constraint c {(s.x + s.x) dist {10 := 9, 20 := 1};}
function new();
s = new;
endfunction
endclass
class RtWeight; class RtWeight;
rand uint x; rand uint x;
uint w; uint w;
@ -259,6 +272,48 @@ module t;
`checkd(m.y, 500); `checkd(m.y, 500);
end end
// Same var twice in the dist expression, frozen: membership of 2*x decides.
begin
DupVar d;
d = new;
ok = d.randomize();
`checkd(ok, 1);
d.x.rand_mode(0);
d.x = 5;
for (int i = 0; i < 8; ++i) begin
ok = d.randomize();
`checkd(ok, 1);
`checkd(d.x, 5);
end
d.x = 7;
for (int i = 0; i < 8; ++i) begin
ok = d.randomize();
`checkd(ok, 0);
`checkd(d.x, 7);
end
end
// Same sub-object member twice in the dist expression, frozen.
begin
DupMember dm;
dm = new;
ok = dm.randomize();
`checkd(ok, 1);
dm.s.x.rand_mode(0);
dm.s.x = 5;
for (int i = 0; i < 8; ++i) begin
ok = dm.randomize();
`checkd(ok, 1);
`checkd(dm.s.x, 5);
end
dm.s.x = 7;
for (int i = 0; i < 8; ++i) begin
ok = dm.randomize();
`checkd(ok, 0);
`checkd(dm.s.x, 7);
end
end
// Runtime weight of zero excludes the bucket's values (18.5.3): frozen // Runtime weight of zero excludes the bucket's values (18.5.3): frozen
// there must fail; nonzero weight on the same frozen value succeeds. // there must fail; nonzero weight on the same frozen value succeeds.
r = new; r = new;