mirror of
https://github.com/verilator/verilator.git
synced 2025-01-05 22:27:35 +00:00
b8417abee5
This patch addresses two issues with NBAs in non-inlined functions/tasks: - If the NBA writes to a local automatic var, the var could cease to exist before the NBA executes. This is normally addressed by fork dynscopes (#4356), but NBA-to-fork transformation happens way after `V3Fork` (in `V3Timing`). To solve this, we put NBAs that write to locals under forks in `V3Fork` already. This way, such locals will be put in dynscopes, and will still exist after the task containing the NBA exits. - The above change means that any writes in forks other than `fork..join` should be handled by `V3Fork`. Thus, in `V3SchedTiming`, we only have to worry about read references, so we can simply copy all remaining locals. Because we copy, lifetimes are not an issue. This fixes a bug that allowed assignment intravals to be overwritten if they go out of scope in the containing function.
77 lines
1.6 KiB
Systemverilog
77 lines
1.6 KiB
Systemverilog
// DESCRIPTION: Verilator: Verilog Test module
|
|
//
|
|
// This file ONLY is placed into the Public Domain, for any use,
|
|
// without warranty, 2023 by Antmicro Ltd.
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
|
|
`ifdef WITH_DELAY
|
|
`define DELAY #1
|
|
`define TIME_AFTER_FIRST_WAIT 2
|
|
`define TIME_AFTER_SECOND_WAIT 3
|
|
`else
|
|
`define DELAY
|
|
`define TIME_AFTER_FIRST_WAIT 1
|
|
`define TIME_AFTER_SECOND_WAIT 1
|
|
`endif
|
|
|
|
class nba_waiter;
|
|
// Task taken from UVM
|
|
task wait_for_nba_region;
|
|
int nba;
|
|
int next_nba;
|
|
next_nba++;
|
|
nba <= `DELAY next_nba;
|
|
@(nba);
|
|
endtask
|
|
endclass
|
|
|
|
class Foo;
|
|
task bar(logic a, logic b);
|
|
int x;
|
|
int y;
|
|
// bar's local vars and intravals could be overwritten by other locals
|
|
if (a) x <= `DELAY 'hDEAD;
|
|
if (b) y <= `DELAY 'hBEEF;
|
|
#2
|
|
if (x != 'hDEAD) $stop;
|
|
endtask
|
|
|
|
task qux();
|
|
int x[] = new[1];
|
|
x[0] <= `DELAY 'hBEEF; // Segfault check
|
|
endtask
|
|
endclass
|
|
|
|
module t;
|
|
nba_waiter waiter = new;
|
|
Foo foo = new;
|
|
event e;
|
|
int cnt = 0;
|
|
|
|
initial begin
|
|
#1 ->e;
|
|
if (cnt != 0) $stop;
|
|
cnt++;
|
|
waiter.wait_for_nba_region;
|
|
->e;
|
|
if (cnt != 2) $stop;
|
|
if ($time != `TIME_AFTER_FIRST_WAIT) $stop;
|
|
cnt++;
|
|
waiter.wait_for_nba_region;
|
|
if (cnt != 4) $stop;
|
|
if ($time != `TIME_AFTER_SECOND_WAIT) $stop;
|
|
foo.bar(1, 1);
|
|
foo.qux();
|
|
#2
|
|
$write("*-* All Finished *-*\n");
|
|
$finish;
|
|
end
|
|
|
|
initial begin
|
|
@e if (cnt != 1) $stop;
|
|
cnt++;
|
|
@e if (cnt != 3) $stop;
|
|
cnt++;
|
|
end
|
|
endmodule
|