From 21b0107bae5365a885004c99e9fad8627d4fbda5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 3 Jul 2026 16:50:35 -0700 Subject: [PATCH] Add regression tests for type identifier task and function names Check that function and task declarations can use a visible type identifier as the declaration name. Cover both ANSI declarations and the non-ANSI forms where the name is parsed without a separate return type or port list. Also check class method declarations where the method name is the same as the enclosing class name. Add GitHub issue #670 coverage for the `function void` case using the issue-based regression naming scheme. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/br_gh670.v | 37 +++++++++++ .../sv_type_identifier_function_name.v | 51 +++++++++++++++ .../ivltests/sv_type_identifier_task_name.v | 62 +++++++++++++++++++ ivtest/regress-vvp.list | 3 + ivtest/vvp_tests/br_gh670.json | 9 +++ .../sv_type_identifier_function_name.json | 9 +++ .../sv_type_identifier_task_name.json | 9 +++ 7 files changed, 180 insertions(+) create mode 100644 ivtest/ivltests/br_gh670.v create mode 100644 ivtest/ivltests/sv_type_identifier_function_name.v create mode 100644 ivtest/ivltests/sv_type_identifier_task_name.v create mode 100644 ivtest/vvp_tests/br_gh670.json create mode 100644 ivtest/vvp_tests/sv_type_identifier_function_name.json create mode 100644 ivtest/vvp_tests/sv_type_identifier_task_name.json diff --git a/ivtest/ivltests/br_gh670.v b/ivtest/ivltests/br_gh670.v new file mode 100644 index 000000000..d267dc51d --- /dev/null +++ b/ivtest/ivltests/br_gh670.v @@ -0,0 +1,37 @@ +// Regression test for GitHub issue #670. +// Check that a class function can have the same name as the class. + +module test; + + reg failed; + + `define check(value, expected, error) \ + if ((value) !== (expected)) begin \ + $display("FAILED(%0d). %s", `__LINE__, error); \ + $display(" expected %0h, got %0h", expected, value); \ + failed = 1'b1; \ + end + + class test; + int value; + + function void test(); + value = 32'd42; + endfunction + endclass + + initial begin + test tst; + + failed = 1'b0; + tst = new; + tst.test(); + + `check(tst.value, 32'd42, "Class function name did not hide class name"); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_type_identifier_function_name.v b/ivtest/ivltests/sv_type_identifier_function_name.v new file mode 100644 index 000000000..eba36bfd8 --- /dev/null +++ b/ivtest/ivltests/sv_type_identifier_function_name.v @@ -0,0 +1,51 @@ +// Check that function names can shadow visible type identifiers. + +typedef int T; +typedef int U; + +module test; + + reg failed; + + `define check(value, expected, error) \ + if ((value) !== (expected)) begin \ + $display("FAILED(%0d). %s", `__LINE__, error); \ + $display(" expected %0h, got %0h", expected, value); \ + failed = 1'b1; \ + end + + function int T(input int value); + return value + 32'd1; + endfunction + + function U; + U = 1'b1; + endfunction + + class C; + function int T(input int value); + return value + 32'd2; + endfunction + + function int C(input int value); + return value + 32'd3; + endfunction + endclass + + initial begin + C c; + + failed = 1'b0; + c = new; + + `check(T(32'd41), 32'd42, "Function name did not hide typedef"); + `check(U(), 1'b1, "Implicit function name did not hide typedef"); + `check(c.T(32'd40), 32'd42, "Class function name did not hide typedef"); + `check(c.C(32'd39), 32'd42, "Class function name did not hide class name"); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_type_identifier_task_name.v b/ivtest/ivltests/sv_type_identifier_task_name.v new file mode 100644 index 000000000..fefcbfc98 --- /dev/null +++ b/ivtest/ivltests/sv_type_identifier_task_name.v @@ -0,0 +1,62 @@ +// Check that task names can shadow visible type identifiers. + +typedef int T; +typedef int U; + +module test; + + reg failed; + + `define check(value, expected, error) \ + if ((value) !== (expected)) begin \ + $display("FAILED(%0d). %s", `__LINE__, error); \ + $display(" expected %0h, got %0h", expected, value); \ + failed = 1'b1; \ + end + + task T(input int value, output int result); + result = value + 32'd1; + endtask + + task U; + output int result; + + result = 32'd33; + endtask + + class C; + task T(input int value, output int result); + result = value + 32'd2; + endtask + + task C(input int value, output int result); + result = value + 32'd3; + endtask + endclass + + initial begin + C c; + int r0; + int r1; + int r2; + int r3; + + failed = 1'b0; + c = new; + + T(32'd41, r0); + U(r1); + c.T(32'd40, r2); + c.C(32'd39, r3); + + `check(r0, 32'd42, "Task name did not hide typedef"); + `check(r1, 32'd33, "Non-ANSI task name did not hide typedef"); + `check(r2, 32'd42, "Class task name did not hide typedef"); + `check(r3, 32'd42, "Class task name did not hide class name"); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index b7bf85cc5..b8a152ca4 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -37,6 +37,7 @@ br_gh440 vvp_tests/br_gh440.json br_gh483a vvp_tests/br_gh483a.json br_gh483b vvp_tests/br_gh483b.json br_gh552 vvp_tests/br_gh552.json +br_gh670 vvp_tests/br_gh670.json br_gh687 vvp_tests/br_gh687.json br_gh703 vvp_tests/br_gh703.json br_gh710a vvp_tests/br_gh710a.json @@ -387,6 +388,7 @@ sv_super_member_fail vvp_tests/sv_super_member_fail.json sv_type_identifier_ams_name_fields vvp_tests/sv_type_identifier_ams_name_fields.json sv_type_identifier_config_name vvp_tests/sv_type_identifier_config_name.json sv_type_identifier_foreach_name vvp_tests/sv_type_identifier_foreach_name.json +sv_type_identifier_function_name vvp_tests/sv_type_identifier_function_name.json sv_type_identifier_genvar_name vvp_tests/sv_type_identifier_genvar_name.json sv_type_identifier_modport_name vvp_tests/sv_type_identifier_modport_name.json sv_type_identifier_module_name vvp_tests/sv_type_identifier_module_name.json @@ -399,6 +401,7 @@ sv_type_identifier_parameter_type_param_name vvp_tests/sv_type_identifier_parame sv_type_identifier_port_name vvp_tests/sv_type_identifier_port_name.json sv_type_identifier_specparam_name vvp_tests/sv_type_identifier_specparam_name.json sv_type_identifier_task_function_argument_name vvp_tests/sv_type_identifier_task_function_argument_name.json +sv_type_identifier_task_name vvp_tests/sv_type_identifier_task_name.json sv_type_identifier_variable_name vvp_tests/sv_type_identifier_variable_name.json sv_type_param_restrict_class1 vvp_tests/sv_type_param_restrict_class1.json sv_type_param_restrict_class2 vvp_tests/sv_type_param_restrict_class2.json diff --git a/ivtest/vvp_tests/br_gh670.json b/ivtest/vvp_tests/br_gh670.json new file mode 100644 index 000000000..5effa2a3f --- /dev/null +++ b/ivtest/vvp_tests/br_gh670.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "br_gh670.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Classes are not supported", + "type" : "CE" + } +} diff --git a/ivtest/vvp_tests/sv_type_identifier_function_name.json b/ivtest/vvp_tests/sv_type_identifier_function_name.json new file mode 100644 index 000000000..4e5ae1920 --- /dev/null +++ b/ivtest/vvp_tests/sv_type_identifier_function_name.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "sv_type_identifier_function_name.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Classes are not supported", + "type" : "CE" + } +} diff --git a/ivtest/vvp_tests/sv_type_identifier_task_name.json b/ivtest/vvp_tests/sv_type_identifier_task_name.json new file mode 100644 index 000000000..b95d47644 --- /dev/null +++ b/ivtest/vvp_tests/sv_type_identifier_task_name.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "sv_type_identifier_task_name.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Classes are not supported", + "type" : "CE" + } +}