From 7a9140821d39114331c922e8f453f182207abd45 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 25 Nov 2024 21:21:11 -0500 Subject: [PATCH] Fix public_module requiring a wire to become public (#4916). --- Changes | 1 + src/V3Dead.cpp | 20 ++++++++++---------- test_regress/t/t_inst_public.py | 19 +++++++++++++++++++ test_regress/t/t_inst_public.v | 31 +++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) create mode 100755 test_regress/t/t_inst_public.py create mode 100644 test_regress/t/t_inst_public.v diff --git a/Changes b/Changes index a429b4e0e..1e028eac2 100644 --- a/Changes +++ b/Changes @@ -33,6 +33,7 @@ Verilator 5.031 devel * Improve concatenation performance (#5598) (#5599) (#5602). [Geza Lore] * Fix dotted reference in delay value (#2410). * Fix `function fork...join_none` regression with unknown type (#4449). +* Fix public_module requiring a wire to become public (#4916). [Andrew Nolte] * Fix can't locate scope error in interface task delayed assignment (#5462) (#5568). [Zhou Shen] * Fix BLKANDNBLK for for VARXREFs (#5569). [Todd Strader] * Fix VPI error instead of fatal for vpi_get_value() on large signals (#5571). [Todd Strader] diff --git a/src/V3Dead.cpp b/src/V3Dead.cpp index a957da964..a0303ccfb 100644 --- a/src/V3Dead.cpp +++ b/src/V3Dead.cpp @@ -109,16 +109,16 @@ class DeadVisitor final : public VNVisitor { if (m_modp) m_modp->user1Inc(); // e.g. Class under Package VL_RESTORER(m_modp); m_modp = nodep; - if (!nodep->dead()) { - iterateChildren(nodep); - checkAll(nodep); - if (AstClass* const classp = VN_CAST(nodep, Class)) { - if (classp->extendsp()) classp->extendsp()->user1Inc(); - if (classp->classOrPackagep()) classp->classOrPackagep()->user1Inc(); - m_classesp.push_back(classp); - // TODO we don't reclaim dead classes yet - graph implementation instead? - classp->user1Inc(); - } + if (nodep->dead()) return; + if (nodep->modPublic()) m_modp->user1Inc(); + iterateChildren(nodep); + checkAll(nodep); + if (AstClass* const classp = VN_CAST(nodep, Class)) { + if (classp->extendsp()) classp->extendsp()->user1Inc(); + if (classp->classOrPackagep()) classp->classOrPackagep()->user1Inc(); + m_classesp.push_back(classp); + // TODO we don't reclaim dead classes yet - graph implementation instead? + classp->user1Inc(); } } void visit(AstCFunc* nodep) override { diff --git a/test_regress/t/t_inst_public.py b/test_regress/t/t_inst_public.py new file mode 100755 index 000000000..c4062aa79 --- /dev/null +++ b/test_regress/t/t_inst_public.py @@ -0,0 +1,19 @@ +#!/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_make_gmake=False) + +test.file_grep(test.obj_dir + "/" + test.vm_prefix + "_Pub.h", r'') +test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + "__Syms.h", r'Dead') + +test.passes() diff --git a/test_regress/t/t_inst_public.v b/test_regress/t/t_inst_public.v new file mode 100644 index 000000000..4b30fab8f --- /dev/null +++ b/test_regress/t/t_inst_public.v @@ -0,0 +1,31 @@ +// 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*/); + + Pub pub(); + + localparam ZERO = 0; + if (ZERO) Dead dead(); + + initial begin + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule + +module Pub; + + // verilator public_module + + // no signals here + +endmodule + +module Dead; + // verilator public_module +endmodule