From e4d29bb1c1126d5862dbfb4cea95da310ce6caed Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 2 Aug 2026 10:26:40 -0700 Subject: [PATCH] Add regression test for cross-unit package imports Check that value parameters, `localparam` constants, scalar variables, unpacked arrays, named events, and enum literals imported from a package in another compilation unit are visible in the importing module. Exercise both explicit and wildcard imports. Give the package declarations larger unit-local lexical positions than the references in the importing unit so that comparing these unrelated positions exposes the bug. Signed-off-by: Lars-Peter Clausen --- .../ivltests/sv_package_import_cross_unit.v | 52 +++++++++++++++++++ .../sv_package_import_cross_unit_pkg.v | 17 ++++++ ivtest/regress-vvp.list | 1 + .../sv_package_import_cross_unit.json | 6 +++ 4 files changed, 76 insertions(+) create mode 100644 ivtest/ivltests/sv_package_import_cross_unit.v create mode 100644 ivtest/ivltests/sv_package_import_cross_unit_pkg.v create mode 100644 ivtest/vvp_tests/sv_package_import_cross_unit.json diff --git a/ivtest/ivltests/sv_package_import_cross_unit.v b/ivtest/ivltests/sv_package_import_cross_unit.v new file mode 100644 index 000000000..ec6a085b7 --- /dev/null +++ b/ivtest/ivltests/sv_package_import_cross_unit.v @@ -0,0 +1,52 @@ +// Check that identifiers imported from another compilation unit are visible +// and do not depend on lexical position. + +module test; + + import p::parameter_value; + import p::variable_value; + import p::event_value; + import p::*; + + localparam integer imported_parameter = parameter_value; + localparam integer imported_localparam = localparam_value; + localparam integer imported_enum = enum_value; + integer imported_variable; + integer imported_array; + reg event_seen; + reg failed; + + always @(event_value) + event_seen = 1'b1; + + `define check(val, exp) \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %b, got %b", `__LINE__, \ + `"val`", exp, val); \ + failed = 1'b1; \ + end + + initial begin + failed = 1'b0; + event_seen = 1'b0; + + #1; + imported_variable = variable_value; + array_value[1] = 53; + imported_array = array_value[1]; + -> event_value; + #1; + + `check(imported_parameter, 17); + `check(imported_localparam, 23); + `check(imported_enum, 31); + `check(imported_variable, 32'd42); + `check(imported_array, 32'd53); + `check(event_seen, 1'b1); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_package_import_cross_unit_pkg.v b/ivtest/ivltests/sv_package_import_cross_unit_pkg.v new file mode 100644 index 000000000..a88b1e863 --- /dev/null +++ b/ivtest/ivltests/sv_package_import_cross_unit_pkg.v @@ -0,0 +1,17 @@ +package p; + + // Make the imported declaration positions greater than the reference + // positions in the separate compilation unit. + integer pad00, pad01, pad02, pad03, pad04, pad05, pad06, pad07; + integer pad08, pad09, pad10, pad11, pad12, pad13, pad14, pad15; + integer pad16, pad17, pad18, pad19, pad20, pad21, pad22, pad23; + integer pad24, pad25, pad26, pad27, pad28, pad29, pad30, pad31; + + integer variable_value = 42; + reg [31:0] array_value [0:1]; + event event_value; + parameter integer parameter_value = 17; + localparam integer localparam_value = 23; + typedef enum integer { enum_value = 31 } enum_type; + +endpackage diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 9af5f385b..abba658b2 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -402,6 +402,7 @@ sv_module_port4 vvp_tests/sv_module_port4.json sv_net_array_decl_assign vvp_tests/sv_net_array_decl_assign.json sv_net_decl_assign vvp_tests/sv_net_decl_assign.json sv_package_import_copy_new vvp_tests/sv_package_import_copy_new.json +sv_package_import_cross_unit vvp_tests/sv_package_import_cross_unit.json sv_package_import_order_dotstar vvp_tests/sv_package_import_order_dotstar.json sv_package_import_order_explicit vvp_tests/sv_package_import_order_explicit.json sv_package_import_order_named vvp_tests/sv_package_import_order_named.json diff --git a/ivtest/vvp_tests/sv_package_import_cross_unit.json b/ivtest/vvp_tests/sv_package_import_cross_unit.json new file mode 100644 index 000000000..7e1357619 --- /dev/null +++ b/ivtest/vvp_tests/sv_package_import_cross_unit.json @@ -0,0 +1,6 @@ +{ + "type" : "normal", + "source" : "sv_package_import_cross_unit.v", + "iverilog-args" : [ "-g2005-sv", "-u", + "ivltests/sv_package_import_cross_unit_pkg.v" ] +}