From c71709d75df81627675d08f5281dc631436a1632 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 2 Aug 2026 11:03:05 -0700 Subject: [PATCH] Add regression tests for `$unit::` reference order Check separately that `$unit::` references to a variable, named event, and parameter declared later in the compilation unit are rejected. Also check that preceding compilation-unit items remain visible and that a later function name remains visible as permitted by the LRM section 3.12.1 exception. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_unit_order_event_fail.v | 9 ++++ .../ivltests/sv_unit_order_parameter_fail.v | 9 ++++ ivtest/ivltests/sv_unit_order_valid.v | 44 +++++++++++++++++++ ivtest/ivltests/sv_unit_order_variable_fail.v | 9 ++++ ivtest/regress-vvp.list | 4 ++ .../vvp_tests/sv_unit_order_event_fail.json | 5 +++ .../sv_unit_order_parameter_fail.json | 5 +++ ivtest/vvp_tests/sv_unit_order_valid.json | 5 +++ .../sv_unit_order_variable_fail.json | 5 +++ 9 files changed, 95 insertions(+) create mode 100644 ivtest/ivltests/sv_unit_order_event_fail.v create mode 100644 ivtest/ivltests/sv_unit_order_parameter_fail.v create mode 100644 ivtest/ivltests/sv_unit_order_valid.v create mode 100644 ivtest/ivltests/sv_unit_order_variable_fail.v create mode 100644 ivtest/vvp_tests/sv_unit_order_event_fail.json create mode 100644 ivtest/vvp_tests/sv_unit_order_parameter_fail.json create mode 100644 ivtest/vvp_tests/sv_unit_order_valid.json create mode 100644 ivtest/vvp_tests/sv_unit_order_variable_fail.json diff --git a/ivtest/ivltests/sv_unit_order_event_fail.v b/ivtest/ivltests/sv_unit_order_event_fail.v new file mode 100644 index 000000000..170f3a4f6 --- /dev/null +++ b/ivtest/ivltests/sv_unit_order_event_fail.v @@ -0,0 +1,9 @@ +// Check that $unit:: does not allow a forward named event reference. + +module test; + + initial -> $unit::value; + +endmodule + +event value; diff --git a/ivtest/ivltests/sv_unit_order_parameter_fail.v b/ivtest/ivltests/sv_unit_order_parameter_fail.v new file mode 100644 index 000000000..2bebb4e93 --- /dev/null +++ b/ivtest/ivltests/sv_unit_order_parameter_fail.v @@ -0,0 +1,9 @@ +// Check that $unit:: does not allow a forward parameter reference. + +module test; + + localparam integer result = $unit::value; + +endmodule + +parameter integer value = 42; diff --git a/ivtest/ivltests/sv_unit_order_valid.v b/ivtest/ivltests/sv_unit_order_valid.v new file mode 100644 index 000000000..225d02812 --- /dev/null +++ b/ivtest/ivltests/sv_unit_order_valid.v @@ -0,0 +1,44 @@ +// Check legal $unit:: references and a forward function reference. + +parameter integer parameter_value = 17; +integer variable_value = 42; +event event_value; + +module test; + + reg event_seen; + reg failed; + + `define check(val, exp) \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %b, got %b", `__LINE__, \ + `"val`", exp, val); \ + failed = 1'b1; \ + end + + always @($unit::event_value) + event_seen = 1'b1; + + initial begin + failed = 1'b0; + event_seen = 1'b0; + + #1; + -> $unit::event_value; + #1; + + `check($unit::parameter_value, 17); + `check($unit::variable_value, 42); + `check(event_seen, 1'b1); + `check($unit::function_value(), 23); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule + +function integer function_value; + function_value = 23; +endfunction diff --git a/ivtest/ivltests/sv_unit_order_variable_fail.v b/ivtest/ivltests/sv_unit_order_variable_fail.v new file mode 100644 index 000000000..dce81a237 --- /dev/null +++ b/ivtest/ivltests/sv_unit_order_variable_fail.v @@ -0,0 +1,9 @@ +// Check that $unit:: does not allow a forward variable reference. + +module test; + + initial $display("%0d", $unit::value); + +endmodule + +integer value; diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 037712e6e..21d0b57b4 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -505,6 +505,10 @@ sv_type_param_restrict_union1 vvp_tests/sv_type_param_restrict_union1.json sv_type_param_restrict_union2 vvp_tests/sv_type_param_restrict_union2.json sv_type_param_restrict_union_fail1 vvp_tests/sv_type_param_restrict_union_fail1.json sv_type_param_restrict_union_fail2 vvp_tests/sv_type_param_restrict_union_fail2.json +sv_unit_order_event_fail vvp_tests/sv_unit_order_event_fail.json +sv_unit_order_parameter_fail vvp_tests/sv_unit_order_parameter_fail.json +sv_unit_order_valid vvp_tests/sv_unit_order_valid.json +sv_unit_order_variable_fail vvp_tests/sv_unit_order_variable_fail.json sv_wildcard_import8 vvp_tests/sv_wildcard_import8.json sv_wildcard_port_order vvp_tests/sv_wildcard_port_order.json sv_wildcard_port_order_relaxed vvp_tests/sv_wildcard_port_order_relaxed.json diff --git a/ivtest/vvp_tests/sv_unit_order_event_fail.json b/ivtest/vvp_tests/sv_unit_order_event_fail.json new file mode 100644 index 000000000..0254ea968 --- /dev/null +++ b/ivtest/vvp_tests/sv_unit_order_event_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_unit_order_event_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_unit_order_parameter_fail.json b/ivtest/vvp_tests/sv_unit_order_parameter_fail.json new file mode 100644 index 000000000..9f1166025 --- /dev/null +++ b/ivtest/vvp_tests/sv_unit_order_parameter_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_unit_order_parameter_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_unit_order_valid.json b/ivtest/vvp_tests/sv_unit_order_valid.json new file mode 100644 index 000000000..ebe52cfc1 --- /dev/null +++ b/ivtest/vvp_tests/sv_unit_order_valid.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_unit_order_valid.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_unit_order_variable_fail.json b/ivtest/vvp_tests/sv_unit_order_variable_fail.json new file mode 100644 index 000000000..965f4ae02 --- /dev/null +++ b/ivtest/vvp_tests/sv_unit_order_variable_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_unit_order_variable_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +}