From bd7f6d3c19b389700b570698bc0a039932f59ce6 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 3 Sep 2025 20:04:41 -0400 Subject: [PATCH] Fix randomize local after parameters applied (#6371). --- Changes | 1 + src/V3LinkDot.cpp | 5 +--- test_regress/t/t_randomize_local_param.py | 16 +++++++++++ test_regress/t/t_randomize_local_param.v | 34 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100755 test_regress/t/t_randomize_local_param.py create mode 100644 test_regress/t/t_randomize_local_param.v diff --git a/Changes b/Changes index a0825e403..ebcdcea2a 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,7 @@ Verilator 5.041 devel * Fix while loop hang on timing-delayed assignment (#6343) (#6354). [Krzysztof Bieganski, Antmicro Ltd.] * Fix V3Hash MacOS ambiguity (#6350). [Lan Zongwei] * Fix cmake APPLE variable (#6351). [Lan Zongwei] +* Fix randomize local after parameters applied (#6371). [Alex Solomatnikov] * Fix package imports not found after parameters applied (#6373). [Alex Solomatnikov] diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 1bf052536..5bb70d099 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -3785,10 +3785,6 @@ class LinkDotResolveVisitor final : public VNVisitor { m_statep->resolveClassOrPackage(m_ds.m_dotSymp, nodep, m_ds.m_dotPos != DP_PACKAGE, false, ":: reference"); } - UASSERT_OBJ(m_statep->forPrimary() - || VN_IS(nodep->classOrPackageNodep(), ParamTypeDType) - || nodep->classOrPackageSkipp(), - nodep, "ClassRef has unlinked class"); // ClassRef's have pins, so track if (nodep->classOrPackageSkipp()) { @@ -3796,6 +3792,7 @@ class LinkDotResolveVisitor final : public VNVisitor { } else if (nodep->name() != "local::") { return; } + AstClass* const refClassp = VN_CAST(nodep->classOrPackageSkipp(), Class); // Make sure any extends() are properly imported within referenced class if (refClassp && !m_statep->forPrimary()) classExtendImport(refClassp); diff --git a/test_regress/t/t_randomize_local_param.py b/test_regress/t/t_randomize_local_param.py new file mode 100755 index 000000000..cca4c9e73 --- /dev/null +++ b/test_regress/t/t_randomize_local_param.py @@ -0,0 +1,16 @@ +#!/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('linter') + +test.lint() + +test.passes() diff --git a/test_regress/t/t_randomize_local_param.v b/test_regress/t/t_randomize_local_param.v new file mode 100644 index 000000000..15c0a8b28 --- /dev/null +++ b/test_regress/t/t_randomize_local_param.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, 2025 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +package Pkg; + virtual class uvm_sequence #( + type REQ = int + ); + REQ m_req; + endclass +endpackage + +package SubPkg; + import Pkg::*; + class s_trgt_txn; + int m_txn_val; + endclass + class p_mem_seq extends uvm_sequence #(s_trgt_txn); + rand bit m_wr_flag; + virtual task body(); + if (0 !== (m_req.randomize() with {local::m_wr_flag;})) begin + end + endtask + endclass +endpackage + +module t; + initial begin + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule