From b3d0677d0832ef5c310e8d217db691e110c7a15f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 11 Aug 2026 08:15:57 -0700 Subject: [PATCH] Add regression tests for task and function call lookup Check that a closer variable, named event, or parameter hides a task or function used as a statement. Also check object method lookup and recursive function calls used as statements. Check that a later compilation-unit task or function takes precedence over a matching subroutine in an enclosing instance. Check that different instances of the same module resolve task calls through their respective enclosing instances. Check ordinary lexical ordering for a task-call receiver declared before or after the reference. Signed-off-by: Lars-Peter Clausen --- .../sv_function_statement_order_event_fail.v | 13 ++++ ..._function_statement_order_parameter_fail.v | 14 +++++ ...v_function_statement_order_variable_fail.v | 14 +++++ .../sv_function_statement_recursive.v | 26 ++++++++ .../sv_function_statement_unit_precedence.v | 33 ++++++++++ .../ivltests/sv_task_call_instance_lookup.v | 60 +++++++++++++++++++ ivtest/ivltests/sv_task_call_object_shadow.v | 36 +++++++++++ .../ivltests/sv_task_call_order_event_fail.v | 13 ++++ .../sv_task_call_order_parameter_fail.v | 13 ++++ .../sv_task_call_order_variable_fail.v | 12 ++++ .../sv_task_call_receiver_unit_order.v | 59 ++++++++++++++++++ .../ivltests/sv_task_call_unit_precedence.v | 33 ++++++++++ ivtest/regress-vvp.list | 12 ++++ ...v_function_statement_order_event_fail.json | 5 ++ ...nction_statement_order_parameter_fail.json | 5 ++ ...unction_statement_order_variable_fail.json | 5 ++ .../sv_function_statement_recursive.json | 9 +++ ...sv_function_statement_unit_precedence.json | 5 ++ .../sv_task_call_instance_lookup.json | 8 +++ .../vvp_tests/sv_task_call_object_shadow.json | 9 +++ .../sv_task_call_order_event_fail.json | 5 ++ .../sv_task_call_order_parameter_fail.json | 5 ++ .../sv_task_call_order_variable_fail.json | 5 ++ .../sv_task_call_receiver_unit_order.json | 9 +++ .../sv_task_call_unit_precedence.json | 5 ++ 25 files changed, 413 insertions(+) create mode 100644 ivtest/ivltests/sv_function_statement_order_event_fail.v create mode 100644 ivtest/ivltests/sv_function_statement_order_parameter_fail.v create mode 100644 ivtest/ivltests/sv_function_statement_order_variable_fail.v create mode 100644 ivtest/ivltests/sv_function_statement_recursive.v create mode 100644 ivtest/ivltests/sv_function_statement_unit_precedence.v create mode 100644 ivtest/ivltests/sv_task_call_instance_lookup.v create mode 100644 ivtest/ivltests/sv_task_call_object_shadow.v create mode 100644 ivtest/ivltests/sv_task_call_order_event_fail.v create mode 100644 ivtest/ivltests/sv_task_call_order_parameter_fail.v create mode 100644 ivtest/ivltests/sv_task_call_order_variable_fail.v create mode 100644 ivtest/ivltests/sv_task_call_receiver_unit_order.v create mode 100644 ivtest/ivltests/sv_task_call_unit_precedence.v create mode 100644 ivtest/vvp_tests/sv_function_statement_order_event_fail.json create mode 100644 ivtest/vvp_tests/sv_function_statement_order_parameter_fail.json create mode 100644 ivtest/vvp_tests/sv_function_statement_order_variable_fail.json create mode 100644 ivtest/vvp_tests/sv_function_statement_recursive.json create mode 100644 ivtest/vvp_tests/sv_function_statement_unit_precedence.json create mode 100644 ivtest/vvp_tests/sv_task_call_instance_lookup.json create mode 100644 ivtest/vvp_tests/sv_task_call_object_shadow.json create mode 100644 ivtest/vvp_tests/sv_task_call_order_event_fail.json create mode 100644 ivtest/vvp_tests/sv_task_call_order_parameter_fail.json create mode 100644 ivtest/vvp_tests/sv_task_call_order_variable_fail.json create mode 100644 ivtest/vvp_tests/sv_task_call_receiver_unit_order.json create mode 100644 ivtest/vvp_tests/sv_task_call_unit_precedence.json diff --git a/ivtest/ivltests/sv_function_statement_order_event_fail.v b/ivtest/ivltests/sv_function_statement_order_event_fail.v new file mode 100644 index 000000000..ec5b5d005 --- /dev/null +++ b/ivtest/ivltests/sv_function_statement_order_event_fail.v @@ -0,0 +1,13 @@ +// Check that a later named event in the local scope hides a compilation-unit +// function used as a statement. + +function void value; +endfunction + +module test; + + initial value(); + + event value; + +endmodule diff --git a/ivtest/ivltests/sv_function_statement_order_parameter_fail.v b/ivtest/ivltests/sv_function_statement_order_parameter_fail.v new file mode 100644 index 000000000..79d735b70 --- /dev/null +++ b/ivtest/ivltests/sv_function_statement_order_parameter_fail.v @@ -0,0 +1,14 @@ +// Check that a later parameter in the local scope hides a compilation-unit +// function used as a statement. + +function integer value; + value = 0; +endfunction + +module test; + + initial value(); + + parameter value = 1; + +endmodule diff --git a/ivtest/ivltests/sv_function_statement_order_variable_fail.v b/ivtest/ivltests/sv_function_statement_order_variable_fail.v new file mode 100644 index 000000000..ec558e0b7 --- /dev/null +++ b/ivtest/ivltests/sv_function_statement_order_variable_fail.v @@ -0,0 +1,14 @@ +// Check that a later local variable hides a compilation-unit function used +// as a statement. + +function integer value; + value = 0; +endfunction + +module test; + + initial value(); + + integer value; + +endmodule diff --git a/ivtest/ivltests/sv_function_statement_recursive.v b/ivtest/ivltests/sv_function_statement_recursive.v new file mode 100644 index 000000000..b23c3ace9 --- /dev/null +++ b/ivtest/ivltests/sv_function_statement_recursive.v @@ -0,0 +1,26 @@ +// Check that a recursive non-void function can call itself as a statement. + +module test; + + integer calls; + + function automatic integer recurse(input integer count); + calls = calls + 1; + if (count > 0) begin + recurse(count - 1); + end + recurse = 0; + endfunction + + initial begin + calls = 0; + recurse(2); + + if (calls == 3) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_function_statement_unit_precedence.v b/ivtest/ivltests/sv_function_statement_unit_precedence.v new file mode 100644 index 000000000..f82cfd09d --- /dev/null +++ b/ivtest/ivltests/sv_function_statement_unit_precedence.v @@ -0,0 +1,33 @@ +// Check that a compilation-unit function takes precedence over a function in +// an enclosing instance when called as a statement. + +integer result; + +module child; + + initial begin + result = 0; + value(); + + if (result == 1) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule + +function void value; + result = 1; +endfunction + +module test; + + child i_child(); + + function void value; + result = 2; + endfunction + +endmodule diff --git a/ivtest/ivltests/sv_task_call_instance_lookup.v b/ivtest/ivltests/sv_task_call_instance_lookup.v new file mode 100644 index 000000000..296bb2d9f --- /dev/null +++ b/ivtest/ivltests/sv_task_call_instance_lookup.v @@ -0,0 +1,60 @@ +// Check that task calls in different instances of the same module are +// resolved through each enclosing instance. + +module child(output reg [7:0] result); + + initial set_value(result); + +endmodule + +module parent_a(output wire [7:0] result); + + task set_value; + output [7:0] result; + result = 8'ha1; + endtask + + child i_child(result); + +endmodule + +module parent_b(output wire [7:0] result); + + task set_value; + output [7:0] result; + result = 8'hb2; + endtask + + child i_child(result); + +endmodule + +module test; + + wire [7:0] result_a; + wire [7:0] result_b; + reg failed; + + parent_a i_parent_a(result_a); + parent_b i_parent_b(result_b); + + `define check(val, exp) \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %h, got %h", `__LINE__, \ + `"val`", exp, val); \ + failed = 1'b1; \ + end + + initial begin + failed = 1'b0; + #1; + + `check(result_a, 8'ha1) + `check(result_b, 8'hb2) + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_task_call_object_shadow.v b/ivtest/ivltests/sv_task_call_object_shadow.v new file mode 100644 index 000000000..368e6cced --- /dev/null +++ b/ivtest/ivltests/sv_task_call_object_shadow.v @@ -0,0 +1,36 @@ +// Check that a local class object hides an outer scope when calling a task +// method. + +class C; + + task run; + $display("PASSED"); + endtask + +endclass + +module object_type; + + task run; + $display("FAILED"); + endtask + +endmodule + +module child; + + C object; + + initial begin + object = new; + object.run(); + end + +endmodule + +module test; + + object_type object(); + child i_child(); + +endmodule diff --git a/ivtest/ivltests/sv_task_call_order_event_fail.v b/ivtest/ivltests/sv_task_call_order_event_fail.v new file mode 100644 index 000000000..d49d43090 --- /dev/null +++ b/ivtest/ivltests/sv_task_call_order_event_fail.v @@ -0,0 +1,13 @@ +// Check that a later named event in the local scope hides a compilation-unit +// task. + +task value; +endtask + +module test; + + initial value(); + + event value; + +endmodule diff --git a/ivtest/ivltests/sv_task_call_order_parameter_fail.v b/ivtest/ivltests/sv_task_call_order_parameter_fail.v new file mode 100644 index 000000000..4491e377a --- /dev/null +++ b/ivtest/ivltests/sv_task_call_order_parameter_fail.v @@ -0,0 +1,13 @@ +// Check that a later parameter in the local scope hides a compilation-unit +// task. + +task value; +endtask + +module test; + + initial value(); + + parameter value = 1; + +endmodule diff --git a/ivtest/ivltests/sv_task_call_order_variable_fail.v b/ivtest/ivltests/sv_task_call_order_variable_fail.v new file mode 100644 index 000000000..59c8a1ca8 --- /dev/null +++ b/ivtest/ivltests/sv_task_call_order_variable_fail.v @@ -0,0 +1,12 @@ +// Check that a later local variable hides a compilation-unit task. + +task value; +endtask + +module test; + + initial value(); + + integer value; + +endmodule diff --git a/ivtest/ivltests/sv_task_call_receiver_unit_order.v b/ivtest/ivltests/sv_task_call_receiver_unit_order.v new file mode 100644 index 000000000..182fb5e87 --- /dev/null +++ b/ivtest/ivltests/sv_task_call_receiver_unit_order.v @@ -0,0 +1,59 @@ +// Check lexical ordering for the receiver of a task call. + +class C; + + task set_value(output integer result); + result = 11; + endtask + +endclass + +C before_object = new; + +module holder; + + task set_value; + output integer result; + result = 22; + endtask + +endmodule + +module child; + + integer before_value; + integer after_value; + reg failed; + + `define check(val, exp) \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, \ + `"val`", exp, val); \ + failed = 1'b1; \ + end + + initial begin + failed = 1'b0; + + before_object.set_value(before_value); + after_object.set_value(after_value); + + `check(before_value, 11) + `check(after_value, 22) + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule + +module test; + + holder before_object(); + holder after_object(); + child child_instance(); + +endmodule + +C after_object = new; diff --git a/ivtest/ivltests/sv_task_call_unit_precedence.v b/ivtest/ivltests/sv_task_call_unit_precedence.v new file mode 100644 index 000000000..f09764431 --- /dev/null +++ b/ivtest/ivltests/sv_task_call_unit_precedence.v @@ -0,0 +1,33 @@ +// Check that a compilation-unit task takes precedence over a task in an +// enclosing instance. + +integer result; + +module child; + + initial begin + result = 0; + value(); + + if (result == 1) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule + +task value; + result = 1; +endtask + +module test; + + child i_child(); + + task value; + result = 2; + endtask + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index dca83d3f4..361ac014e 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -362,6 +362,11 @@ sv_function_call_chain_unit_precedence vvp_tests/sv_function_call_chain_unit_pre sv_function_call_receiver_unit_order vvp_tests/sv_function_call_receiver_unit_order.json sv_function_call_unit_import_precedence vvp_tests/sv_function_call_unit_import_precedence.json sv_function_call_unit_precedence vvp_tests/sv_function_call_unit_precedence.json +sv_function_statement_order_event_fail vvp_tests/sv_function_statement_order_event_fail.json +sv_function_statement_order_parameter_fail vvp_tests/sv_function_statement_order_parameter_fail.json +sv_function_statement_order_variable_fail vvp_tests/sv_function_statement_order_variable_fail.json +sv_function_statement_recursive vvp_tests/sv_function_statement_recursive.json +sv_function_statement_unit_precedence vvp_tests/sv_function_statement_unit_precedence.json sv_interface vvp_tests/sv_interface.json sv_interface_identifier_block_name vvp_tests/sv_interface_identifier_block_name.json sv_interface_identifier_instance_name vvp_tests/sv_interface_identifier_instance_name.json @@ -470,7 +475,14 @@ sv_soft_packed_union vvp_tests/sv_soft_packed_union.json sv_soft_packed_union_fail1 vvp_tests/sv_soft_packed_union_fail1.json sv_string_method_substr_too_few_arg_fail vvp_tests/sv_string_method_substr_too_few_arg_fail.json sv_super_member_fail vvp_tests/sv_super_member_fail.json +sv_task_call_instance_lookup vvp_tests/sv_task_call_instance_lookup.json +sv_task_call_object_shadow vvp_tests/sv_task_call_object_shadow.json +sv_task_call_order_event_fail vvp_tests/sv_task_call_order_event_fail.json +sv_task_call_order_parameter_fail vvp_tests/sv_task_call_order_parameter_fail.json +sv_task_call_order_variable_fail vvp_tests/sv_task_call_order_variable_fail.json sv_task_call_receiver_unit_precedence vvp_tests/sv_task_call_receiver_unit_precedence.json +sv_task_call_receiver_unit_order vvp_tests/sv_task_call_receiver_unit_order.json +sv_task_call_unit_precedence vvp_tests/sv_task_call_unit_precedence.json sv_type_identifier_ams_name_fields vvp_tests/sv_type_identifier_ams_name_fields.json sv_type_identifier_assert_item_label vvp_tests/sv_type_identifier_assert_item_label.json sv_type_identifier_assert_label vvp_tests/sv_type_identifier_assert_label.json diff --git a/ivtest/vvp_tests/sv_function_statement_order_event_fail.json b/ivtest/vvp_tests/sv_function_statement_order_event_fail.json new file mode 100644 index 000000000..257f3a993 --- /dev/null +++ b/ivtest/vvp_tests/sv_function_statement_order_event_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_function_statement_order_event_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_function_statement_order_parameter_fail.json b/ivtest/vvp_tests/sv_function_statement_order_parameter_fail.json new file mode 100644 index 000000000..7b345a55e --- /dev/null +++ b/ivtest/vvp_tests/sv_function_statement_order_parameter_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_function_statement_order_parameter_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_function_statement_order_variable_fail.json b/ivtest/vvp_tests/sv_function_statement_order_variable_fail.json new file mode 100644 index 000000000..e660eeb6c --- /dev/null +++ b/ivtest/vvp_tests/sv_function_statement_order_variable_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_function_statement_order_variable_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_function_statement_recursive.json b/ivtest/vvp_tests/sv_function_statement_recursive.json new file mode 100644 index 000000000..db79f667d --- /dev/null +++ b/ivtest/vvp_tests/sv_function_statement_recursive.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "sv_function_statement_recursive.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Automatic functions are not supported", + "type" : "CE" + } +} diff --git a/ivtest/vvp_tests/sv_function_statement_unit_precedence.json b/ivtest/vvp_tests/sv_function_statement_unit_precedence.json new file mode 100644 index 000000000..06e52cc02 --- /dev/null +++ b/ivtest/vvp_tests/sv_function_statement_unit_precedence.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_function_statement_unit_precedence.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_task_call_instance_lookup.json b/ivtest/vvp_tests/sv_task_call_instance_lookup.json new file mode 100644 index 000000000..1d8a34c30 --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_instance_lookup.json @@ -0,0 +1,8 @@ +{ + "type" : "normal", + "source" : "sv_task_call_instance_lookup.v", + "vlog95" : { + "__comment" : "vlog95 cannot preserve instance-dependent subroutine binding", + "type" : "NI" + } +} diff --git a/ivtest/vvp_tests/sv_task_call_object_shadow.json b/ivtest/vvp_tests/sv_task_call_object_shadow.json new file mode 100644 index 000000000..d696c218b --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_object_shadow.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "sv_task_call_object_shadow.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Class scopes are not currently translated", + "type" : "CE" + } +} diff --git a/ivtest/vvp_tests/sv_task_call_order_event_fail.json b/ivtest/vvp_tests/sv_task_call_order_event_fail.json new file mode 100644 index 000000000..63107d74b --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_order_event_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_task_call_order_event_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_task_call_order_parameter_fail.json b/ivtest/vvp_tests/sv_task_call_order_parameter_fail.json new file mode 100644 index 000000000..39dce9753 --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_order_parameter_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_task_call_order_parameter_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_task_call_order_variable_fail.json b/ivtest/vvp_tests/sv_task_call_order_variable_fail.json new file mode 100644 index 000000000..520d63330 --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_order_variable_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_task_call_order_variable_fail.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_task_call_receiver_unit_order.json b/ivtest/vvp_tests/sv_task_call_receiver_unit_order.json new file mode 100644 index 000000000..eb1b47d7d --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_receiver_unit_order.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "sv_task_call_receiver_unit_order.v", + "iverilog-args" : [ "-g2012" ], + "vlog95" : { + "__comment" : "Class scopes are not currently translated", + "type" : "CE" + } +} diff --git a/ivtest/vvp_tests/sv_task_call_unit_precedence.json b/ivtest/vvp_tests/sv_task_call_unit_precedence.json new file mode 100644 index 000000000..f0342a024 --- /dev/null +++ b/ivtest/vvp_tests/sv_task_call_unit_precedence.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_task_call_unit_precedence.v", + "iverilog-args" : [ "-g2005-sv" ] +}