From b6f292f556e1e703eb68e289835c43d926b17c82 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Mon, 2 Dec 2024 15:08:47 -0500 Subject: [PATCH] Fix imported array assignment literals (#5642) (#5648) --- src/V3LinkDot.cpp | 5 ++++- test_regress/t/t_param_pattern_init.v | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 0cbc5bc79..9a5933af2 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2779,7 +2779,10 @@ class LinkDotResolveVisitor final : public VNVisitor { if (AstVar* const varp = VN_CAST(foundp->nodep(), Var)) { if (varp->isParam() || varp->isGenVar()) { // Attach found Text reference to PatMember - nodep->varrefp(new AstVarRef{nodep->fileline(), varp, VAccess::READ}); + nodep->varrefp( + new AstVarRef{nodep->fileline(), + foundp->imported() ? foundp->classOrPackagep() : nullptr, + varp, VAccess::READ}); UINFO(9, indent() << " new " << nodep->varrefp() << endl); } } diff --git a/test_regress/t/t_param_pattern_init.v b/test_regress/t/t_param_pattern_init.v index f175e4bcf..69fefffec 100644 --- a/test_regress/t/t_param_pattern_init.v +++ b/test_regress/t/t_param_pattern_init.v @@ -7,6 +7,15 @@ `define stop $stop `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0); +package some_pkg; + localparam FOO = 5; + localparam BAR = 6; + + typedef enum int { + QUX = 7 + } pkg_enum_t; +endpackage + module t (/*AUTOARG*/ // Inputs clk @@ -69,6 +78,22 @@ module t (/*AUTOARG*/ `checkh(enum_array[2], 32'ha5a5); end + logic [31:0] package_array [8]; + + import some_pkg::*; + always_comb package_array = '{ + FOO: 32'h9876, + BAR: 32'h1212, + QUX: 32'h5432, + default: 0 + }; + + always_ff @(posedge clk) begin + `checkh(package_array[5], 32'h9876); + `checkh(package_array[6], 32'h1212); + `checkh(package_array[7], 32'h5432); + end + always_ff @(posedge clk) begin cyc <= cyc + 1; if (cyc == 2) begin