From cc7928532a6496aea409197ae983d8aead65eca2 Mon Sep 17 00:00:00 2001 From: Krzysztof Bieganski Date: Tue, 17 Oct 2023 22:44:48 +0200 Subject: [PATCH] Do not remap local assign intravals in forks Signed-off-by: Krzysztof Bieganski --- src/V3SchedTiming.cpp | 18 +++++++++++------- test_regress/t/t_fork_jumpblock.pl | 23 +++++++++++++++++++++++ test_regress/t/t_fork_jumpblock.v | 23 +++++++++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100755 test_regress/t/t_fork_jumpblock.pl create mode 100644 test_regress/t/t_fork_jumpblock.v diff --git a/src/V3SchedTiming.cpp b/src/V3SchedTiming.cpp index e072814e72f..b5cbea152e9 100644 --- a/src/V3SchedTiming.cpp +++ b/src/V3SchedTiming.cpp @@ -293,13 +293,17 @@ void transformForks(AstNetlist* const netlistp) { AstVar* const varp = refp->varp(); AstBasicDType* const dtypep = varp->dtypep()->basicp(); bool passByValue = false; - if (VString::startsWith(varp->name(), "__Vintra")) { - // Pass it by value to the new function, as otherwise there are issues with - // -flocalize (see t_timing_intra_assign) - passByValue = true; - } else if (!varp->user1() || !varp->isFuncLocal()) { - // Not func local, or not declared before the fork. Their lifetime is longer - // than the forked process. Skip + if (!varp->isFuncLocal()) { + if (VString::startsWith(varp->name(), "__Vintra")) { + // Pass it by value to the new function, as otherwise there are issues with + // -flocalize (see t_timing_intra_assign) + passByValue = true; + } else { + // Not func local. Its lifetime is longer than the forked process. Skip + return; + } + } else if (!varp->user1()) { + // Not declared before the fork. It cannot outlive the forked process return; } else if (dtypep && dtypep->isForkSync()) { // We can just pass it by value to the new function diff --git a/test_regress/t/t_fork_jumpblock.pl b/test_regress/t/t_fork_jumpblock.pl new file mode 100755 index 00000000000..bc632ee012e --- /dev/null +++ b/test_regress/t/t_fork_jumpblock.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2019 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( + verilator_flags2 => ["--exe --main --timing"], + make_main => 0, + ); + +execute( + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_fork_jumpblock.v b/test_regress/t/t_fork_jumpblock.v new file mode 100644 index 00000000000..13ef8e9f3d1 --- /dev/null +++ b/test_regress/t/t_fork_jumpblock.v @@ -0,0 +1,23 @@ +// 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 + +class bar; + task foo(logic r); + int a, b; + if (r) return; + fork a = #1 b; join_none + endtask +endclass + +module t; + bar b = new; + + initial begin + b.foo(0); + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule