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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-08-02 10:26:40 -07:00
parent da0adf6614
commit e4d29bb1c1
4 changed files with 76 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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" ]
}