Fix constant function calls with uninit value (#2995).

This commit is contained in:
Wilson Snyder 2021-05-31 22:46:41 -04:00
parent e1f9fffb42
commit 2143bcfad5
4 changed files with 66 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Verilator 4.203 devel
* Fix initialization of assoc in assoc array (#2914). [myftptoyman]
* Fix merging of assignments in C++ code (#2970). [Ruper Swarbrick]
* Fix --protect-ids when using SV classes (#2994). [Geza Lore]
* Fix constant function calls with uninit value (#2995). [yanx21]
Verilator 4.202 2021-04-24

View File

@ -979,6 +979,17 @@ private:
}
SimStackNode stackNode(nodep, &tconnects);
m_callStack.push_front(&stackNode);
// Clear output variable
if (auto* const basicp = VN_CAST(funcp->fvarp(), Var)->basicp()) {
AstConst cnst(funcp->fvarp()->fileline(), AstConst::WidthedValue(), basicp->widthMin(),
0);
if (basicp->isZeroInit()) {
cnst.num().setAllBits0();
} else {
cnst.num().setAllBitsX();
}
newValue(funcp->fvarp(), &cnst);
}
// Evaluate the function
iterate(funcp);
m_callStack.pop_front();

21
test_regress/t/t_func_uninit.pl Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2021 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
scenarios(simulator => 1);
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,33 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2021 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
function int zeroed;
endfunction
function automatic integer what_bit;
input [31:0] a;
// what_bit = 0;
for (int i = 31; i >= 0; i = i - 1) begin
if (a[i] == 1'b1) begin
what_bit = i;
end
end
endfunction
module t(/*AUTOARG*/);
parameter ZERO = zeroed();
parameter PP = what_bit(0);
initial begin
if (ZERO != 0) $stop;
if (PP != 'x) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule