Don't pick initial random values for verilator-created variables (#6611)

This commit is contained in:
Todd Strader 2025-11-04 16:11:53 -05:00 committed by GitHub
parent 2c01aff2b3
commit 94d0513bc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 0 deletions

View File

@ -670,6 +670,7 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, bool constructing,
|| varp->isFuncLocal() // Randomization too slow
|| (basicp && basicp->isZeroInit())
|| (v3Global.opt.underlineZero() && !varp->name().empty() && varp->name()[0] == '_')
|| (varp->varType().isTemp() && !varp->isXTemp())
|| (varp->isXTemp()
? (v3Global.opt.xAssign() != "unique")
: (v3Global.opt.xInitial() == "fast" || v3Global.opt.xInitial() == "0")));

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_st")
test.compile(verilator_flags2=["--assert", "-fno-localize"])
test.execute(all_run_flags=["+verilator+rand+reset+2"])
test.passes()

View File

@ -0,0 +1,50 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module other_sub (
input wire clk,
input wire foo,
output logic [5:0] bar
);
always_comb bar[0] = foo;
`ifndef NO_ASSERT
assert property (@(posedge clk) (foo == bar[0]));
`endif
always_ff @(posedge clk) bar[5:1] <= bar[4:0];
endmodule
interface intf
(input wire clk);
endinterface
module sub (
input logic clk
);
for (genvar k = 0; k < 4; k++) begin
logic [5:0] bar;
other_sub
the_other_sub (
.clk,
.foo ('1),
.bar
);
end
endmodule
module t (/*AUTOARG*/
clk
);
input clk;
int cyc = 0;
always @ (posedge clk) begin
cyc <= cyc + 1;
if (cyc == 9) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
sub the_sub (.*);
endmodule