diff --git a/Changes b/Changes index 789983199..8747aa757 100644 --- a/Changes +++ b/Changes @@ -46,6 +46,7 @@ Verilator 5.041 devel * Fix parameter implicit type from string (#6414). [Alex Solomatnikov] * Fix parsing for sequence expressions (#6427). [Bartłomiej Chmiel, Antmicro Ltd.] * Fix resolving parameters (#6388) (#6418) (#6421) (#6438) (#6429). [Artur Bieniek, Antmicro Ltd.] +* Fix external function declarations with class typedef references (#6433). Verilator 5.040 2025-08-30 diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index c2f1e0486..177227934 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -917,6 +917,14 @@ class LinkDotFindVisitor final : public VNVisitor { classp->addStmtsp(nodep); nodep->isExternDef(true); // So we check there's a matching extern nodep->classOrPackagep()->unlinkFrBack()->deleteTree(); + // Any "Type::" reference in the function's IO are really "MovedToClass::" references + if (nodep->fvarp()) + nodep->fvarp()->foreach([this, classp](AstClassOrPackageRef* refp) { // + if (refp->name() == classp->name() && !refp->paramsp()) { + UINFO(9, "Cleaning up external function type for class " << refp); + pushDeletep(refp->unlinkFrBack()); + } + }); } } diff --git a/test_regress/t/t_class_extern_typeref.py b/test_regress/t/t_class_extern_typeref.py new file mode 100755 index 000000000..f989a35fb --- /dev/null +++ b/test_regress/t/t_class_extern_typeref.py @@ -0,0 +1,18 @@ +#!/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('simulator') + +test.compile() + +test.execute() + +test.passes() diff --git a/test_regress/t/t_class_extern_typeref.v b/test_regress/t/t_class_extern_typeref.v new file mode 100644 index 000000000..3501ecb91 --- /dev/null +++ b/test_regress/t/t_class_extern_typeref.v @@ -0,0 +1,28 @@ +// 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 + +class uvm_process_guard#(type T=int); + T m_context; + extern function T get_context(); +endclass + +// When this moves into class, note it's not uvm_process_guard#()::T +// but rather the T specific to the parameterized class +function uvm_process_guard::T uvm_process_guard::get_context(); + return this.m_context; +endfunction + +class uvm_sequence_base; + typedef uvm_process_guard#(uvm_sequence_base) m_guard_t; +endclass + +module t; + initial begin + uvm_sequence_base c; + c = new; + $finish; + end +endmodule