Add regression tests for package variable lifetimes

Check that package variables can use explicit static lifetime. Check that
automatic lifetime is rejected for package variables.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-05-06 22:18:43 -07:00
parent c2b63e69a4
commit 81222402c7
5 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,40 @@
// Check that static lifetime can be specified for variables declared in a
// package.
`define check(val, exp) \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %b, got %b", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end
package P;
static int x = 1;
const static int y = 2;
var static z;
var static logic [3:0] w = 4'h3;
endpackage
package automatic Q;
int a = 4;
static int b = 5;
endpackage
module test;
import P::*;
import Q::*;
bit failed = 1'b0;
initial begin
`check(x, 1)
`check(y, 2)
`check(z, 1'bx)
`check(w, 4'h3)
`check(a, 4)
`check(b, 5)
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,6 @@
// Check that automatic lifetime cannot be specified for variables declared in
// a package.
package P;
automatic int x;
endpackage

View File

@ -280,6 +280,8 @@ sv_module_port1 vvp_tests/sv_module_port1.json
sv_module_port2 vvp_tests/sv_module_port2.json
sv_module_port3 vvp_tests/sv_module_port3.json
sv_module_port4 vvp_tests/sv_module_port4.json
sv_package_lifetime vvp_tests/sv_package_lifetime.json
sv_package_lifetime_fail vvp_tests/sv_package_lifetime_fail.json
sv_parameter_type vvp_tests/sv_parameter_type.json
sv_queue_assign_op vvp_tests/sv_queue_assign_op.json
sv_wildcard_import8 vvp_tests/sv_wildcard_import8.json

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_package_lifetime.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_package_lifetime_fail.v",
"iverilog-args" : [ "-g2005-sv" ]
}