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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-08-11 08:15:57 -07:00
parent 7c5c1acf02
commit b3d0677d08
25 changed files with 413 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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_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_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_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 vvp_tests/sv_interface.json
sv_interface_identifier_block_name vvp_tests/sv_interface_identifier_block_name.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 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_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_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_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_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_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_item_label vvp_tests/sv_type_identifier_assert_item_label.json
sv_type_identifier_assert_label vvp_tests/sv_type_identifier_assert_label.json sv_type_identifier_assert_label vvp_tests/sv_type_identifier_assert_label.json

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,8 @@
{
"type" : "normal",
"source" : "sv_task_call_instance_lookup.v",
"vlog95" : {
"__comment" : "vlog95 cannot preserve instance-dependent subroutine binding",
"type" : "NI"
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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