From 371a4055b0d93079f3c4b5d627edb4010faf0637 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 18 Sep 2024 21:20:17 -0400 Subject: [PATCH] Fix false LIFETIME warning on `repeat` in `fork-join` (#5456). --- Changes | 3 ++- src/V3LinkJump.cpp | 8 +++++--- test_regress/t/t_debug_emitv.out | 14 +++++++------ test_regress/t/t_fork_repeat.py | 18 +++++++++++++++++ test_regress/t/t_fork_repeat.v | 34 ++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100755 test_regress/t/t_fork_repeat.py create mode 100644 test_regress/t/t_fork_repeat.v diff --git a/Changes b/Changes index 78996b4b3..f1ce5d9c7 100644 --- a/Changes +++ b/Changes @@ -247,9 +247,10 @@ Verilator 5.024 2024-04-05 * Fix preprocessor to respect strings in joins (#5007). * Fix tracing class parameters (#5014). * Fix memory leaks (#5016). [Geza Lore] -* Fix $readmem with missing newline (#5019). [Josse Van Delm] +* Fix `$readmem` with missing newline (#5019). [Josse Van Delm] * Fix internal error on missing pattern key (#5023). * Fix tracing replicated hierarchical models (#5027). +* Fix false LIFETIME warning on `repeat` in `fork-join` (#5456). Verilator 5.022 2024-02-24 diff --git a/src/V3LinkJump.cpp b/src/V3LinkJump.cpp index 2bc85cab3..7919b9ecb 100644 --- a/src/V3LinkJump.cpp +++ b/src/V3LinkJump.cpp @@ -202,12 +202,13 @@ class LinkJumpVisitor final : public VNVisitor { // Note var can be signed or unsigned based on original number. AstNodeExpr* const countp = nodep->countp()->unlinkFrBackWithNext(); const string name = "__Vrepeat"s + cvtToStr(m_modRepeatNum++); + AstBegin* const beginp = new AstBegin{nodep->fileline(), "", nullptr, false, true}; // Spec says value is integral, if negative is ignored AstVar* const varp = new AstVar{nodep->fileline(), VVarType::BLOCKTEMP, name, nodep->findSigned32DType()}; varp->lifetime(VLifetime::AUTOMATIC); varp->usedLoopIdx(true); - m_modp->addStmtsp(varp); + beginp->addStmtsp(varp); AstNode* initsp = new AstAssign{ nodep->fileline(), new AstVarRef{nodep->fileline(), varp, VAccess::WRITE}, countp}; AstNode* const decp = new AstAssign{ @@ -222,8 +223,9 @@ class LinkJumpVisitor final : public VNVisitor { AstWhile* const whilep = new AstWhile{nodep->fileline(), condp, bodysp, decp}; if (!m_unrollFull.isDefault()) whilep->unrollFull(m_unrollFull); m_unrollFull = VOptionBool::OPT_DEFAULT_FALSE; - initsp = initsp->addNext(whilep); - nodep->replaceWith(initsp); + beginp->addStmtsp(initsp); + beginp->addStmtsp(whilep); + nodep->replaceWith(beginp); VL_DO_DANGLING(nodep->deleteTree(), nodep); } void visit(AstWhile* nodep) override { diff --git a/test_regress/t/t_debug_emitv.out b/test_regress/t/t_debug_emitv.out index b9bf11b67..689bab73a 100644 --- a/test_regress/t/t_debug_emitv.out +++ b/test_regress/t/t_debug_emitv.out @@ -297,18 +297,20 @@ module Vt_debug_emitv_t; $display("%g", $acosh(r)); $display("%g", $atanh(r)); force sum = 'sha; - __Vrepeat0 = 'sh2; - while ((__Vrepeat0 > 32'h0)) begin - if ((sum != 'sha)) begin - $stop; + begin : unnamedblk1_1 + integer signed [31:0] __Vrepeat0; + __Vrepeat0 = 'sh2; + while ((__Vrepeat0 > 32'h0)) begin + if ((sum != 'sha)) begin + $stop; + end + __Vrepeat0 = (__Vrepeat0 - 32'h1); end - __Vrepeat0 = (__Vrepeat0 - 32'h1); end release sum; end end /*verilator public_flat_rw @(posedge clk) pubflat*/ - integer signed [31:0] __Vrepeat0; endmodule package Vt_debug_emitv___024unit; class Vt_debug_emitv_Cls; diff --git a/test_regress/t/t_fork_repeat.py b/test_regress/t/t_fork_repeat.py new file mode 100755 index 000000000..c53b55262 --- /dev/null +++ b/test_regress/t/t_fork_repeat.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 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(verilator_flags2=["--binary"]) + +test.execute() + +test.passes() diff --git a/test_regress/t/t_fork_repeat.v b/test_regress/t/t_fork_repeat.v new file mode 100644 index 000000000..388584070 --- /dev/null +++ b/test_regress/t/t_fork_repeat.v @@ -0,0 +1,34 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2024 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +module t(/*AUTOARG*/); + bit clk; + + // Gen Clock + always #10 + clk = ~clk; + + initial begin + fork + begin + forever + @(posedge clk); + end + begin + repeat(10) + @(posedge clk); + end + begin + for(int i=0; i < 6; ++i) + @(posedge clk); + end + join_any + + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule