Fix of deleting linked node in V3Randomize (#6718)

Signed-off-by: Igor Zaworski <izaworski@internships.antmicro.com>
This commit is contained in:
Igor Zaworski 2025-11-21 13:07:50 +01:00 committed by GitHub
parent 0b8c369740
commit 98d0eac149
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 2 deletions

View File

@ -900,7 +900,7 @@ class ConstraintExprVisitor final : public VNVisitor {
// Track this variable path as written
if (isGlobalConstrained) m_writtenVars.insert(smtName);
// For global constraints, delete nodep after processing
if (isGlobalConstrained) VL_DO_DANGLING(pushDeletep(nodep), nodep);
if (isGlobalConstrained && !nodep->backp()) VL_DO_DANGLING(pushDeletep(nodep), nodep);
AstCMethodHard* const methodp = new AstCMethodHard{
varp->fileline(),
new AstVarRef{varp->fileline(), VN_AS(m_genp->user2p(), NodeModule), m_genp,
@ -958,7 +958,7 @@ class ConstraintExprVisitor final : public VNVisitor {
// Variable already written, clean up cloned membersel if any
if (membersel) VL_DO_DANGLING(membersel->deleteTree(), membersel);
// Delete nodep if it's a global constraint (not deleted yet)
if (isGlobalConstrained) VL_DO_DANGLING(pushDeletep(nodep), nodep);
if (isGlobalConstrained && !nodep->backp()) VL_DO_DANGLING(pushDeletep(nodep), nodep);
}
}
void visit(AstCountOnes* nodep) override {

View File

@ -0,0 +1,18 @@
#!/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')
test.compile()
test.execute()
test.passes()

View File

@ -0,0 +1,36 @@
// 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 RandomValue;
rand int value;
constraint small_int_c {
value < 10;
}
task disable_val();
value.rand_mode(0);
endtask
endclass
class Base;
endclass
class Foo extends Base;
rand RandomValue v = new;
endclass
module t;
Base b;
initial begin
Foo d = new;
b = d;
d.v.disable_val();
d.v.value = 11;
if (bit'(b.randomize())) $stop;
if (d.v.value != 11) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule