Fix rand variable inside constraint (#6315)

This commit is contained in:
Igor Zaworski 2025-09-04 12:19:08 +02:00 committed by GitHub
parent 5f0eb007b1
commit 4070db9990
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 6 deletions

View File

@ -913,12 +913,6 @@ class ConstraintExprVisitor final : public VNVisitor {
if (nodep->user1()) {
nodep->v3warn(CONSTRAINTIGN, "Global constraints ignored (unsupported)");
}
if (VN_IS(nodep->fromp(), NodeVarRef) && nodep->varp()->isRand() && m_inlineInitTaskp) {
iterateChildren(nodep);
nodep->replaceWith(nodep->fromp()->unlinkFrBack());
VL_DO_DANGLING(nodep->deleteTree(), nodep);
return;
}
editFormat(nodep);
}
void visit(AstSFormatF* nodep) override {}

View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
if not test.have_solver:
test.skip("No constraint solver installed")
test.compile()
test.execute()
test.passes()

View File

@ -0,0 +1,31 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Antmicro.
// SPDX-License-Identifier: CC0-1.0
class A;
rand int j;
endclass
class B;
A a;
rand int i;
function new();
a = new;
i = 7;
endfunction
task r();
if (a.randomize() with { j == i; } == 0) $stop;
endtask
endclass
module t;
initial begin
B b = new;
b.r();
if (b.a.j != 7) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule