From 83081aaefc1a89ce9c38d1102e9ad5029009f247 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Thu, 24 Oct 2024 18:50:57 -0400 Subject: [PATCH] Fix struct literal on pattern assignment (#5552) (#5559) --- src/V3Width.cpp | 2 +- test_regress/t/t_struct_literal_param.py | 18 +++++++++++ test_regress/t/t_struct_literal_param.v | 38 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100755 test_regress/t/t_struct_literal_param.py create mode 100644 test_regress/t/t_struct_literal_param.v diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 8220b133a..1f7c25235 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5544,7 +5544,7 @@ class WidthVisitor final : public VNVisitor { userIterate(modVarp->childDTypep(), WidthVP{SELF, BOTH}.p()); // May relink pointed to node AstNodeDType* const setDtp = modVarp->childDTypep()->cloneTree(false); - patternp->childDTypep(setDtp); + if (!patternp->childDTypep()) patternp->childDTypep(setDtp); userIterateChildren(nodep, WidthVP{setDtp, BOTH}.p()); didWidth = true; } diff --git a/test_regress/t/t_struct_literal_param.py b/test_regress/t/t_struct_literal_param.py new file mode 100755 index 000000000..7e2071c5d --- /dev/null +++ b/test_regress/t/t_struct_literal_param.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=["--debug"]) + +test.execute() + +test.passes() diff --git a/test_regress/t/t_struct_literal_param.v b/test_regress/t/t_struct_literal_param.v new file mode 100644 index 000000000..1e4ff1a2c --- /dev/null +++ b/test_regress/t/t_struct_literal_param.v @@ -0,0 +1,38 @@ +// DESCRIPTION: Verilator: Demonstrate struct literal param assignment problem +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2024 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +package Some_pkg; + typedef struct packed { + int foo; + } some_struct_t; +endpackage + +module sub #( + parameter Some_pkg::some_struct_t the_some_struct +) (); +endmodule + +module t (/*AUTOARG*/ + // Inputs + clk + ); + + input clk; + + // finish report + always @ (posedge clk) begin + $write("*-* All Finished *-*\n"); + $finish; + end + + sub #( + .the_some_struct( + Some_pkg::some_struct_t'{ + foo: 1 + })) + the_sub (); + +endmodule