From fe5e60840f26520e726011c8f591f7ffa9d934f4 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 8 Jan 2023 21:30:47 -0800 Subject: [PATCH] Add regression test for function calls with empty arguments Check that function calls with empty arguments are supported. Check the general case and special cases such as calling a function with empty arguments as part of a module port binding or force statements in automatic contexts. Also check that calling a function with too many trailing empty arguments as well as passing an empty argument for a port without a default value is an error. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/func_empty_arg1.v | 33 +++++++++++++++++++++ ivtest/ivltests/func_empty_arg2.v | 29 ++++++++++++++++++ ivtest/ivltests/func_empty_arg3.v | 41 ++++++++++++++++++++++++++ ivtest/ivltests/func_empty_arg_fail1.v | 16 ++++++++++ ivtest/ivltests/func_empty_arg_fail2.v | 16 ++++++++++ ivtest/ivltests/func_empty_arg_fail3.v | 16 ++++++++++ ivtest/ivltests/func_empty_arg_fail4.v | 16 ++++++++++ ivtest/regress-sv.list | 7 +++++ ivtest/regress-vlog95.list | 1 + 9 files changed, 175 insertions(+) create mode 100644 ivtest/ivltests/func_empty_arg1.v create mode 100644 ivtest/ivltests/func_empty_arg2.v create mode 100644 ivtest/ivltests/func_empty_arg3.v create mode 100644 ivtest/ivltests/func_empty_arg_fail1.v create mode 100644 ivtest/ivltests/func_empty_arg_fail2.v create mode 100644 ivtest/ivltests/func_empty_arg_fail3.v create mode 100644 ivtest/ivltests/func_empty_arg_fail4.v diff --git a/ivtest/ivltests/func_empty_arg1.v b/ivtest/ivltests/func_empty_arg1.v new file mode 100644 index 000000000..107370094 --- /dev/null +++ b/ivtest/ivltests/func_empty_arg1.v @@ -0,0 +1,33 @@ +// Check that it is possible to call functins with empty arguments if they have +// default values. + +module test; + + bit failed = 1'b0; + + `define check(expr, val) \ + if (expr !== val) begin \ + $display("FAILED. %s, expected %d, got %d", `"expr`", val, expr); \ + failed = 1'b1; \ + end + + function integer f(integer a = 1, integer b = 2, integer c = 3); + return a * 100 + b * 10 + c; + endfunction + + initial begin + `check(f(4, 5, 6), 456); + `check(f(4, 5, ), 453); + `check(f(4, , 6), 426); + `check(f( , 5, 6), 156); + `check(f(4, , ), 423); + `check(f( , 5, ), 153); + `check(f( , , 6), 126); + `check(f( , , ), 123); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/func_empty_arg2.v b/ivtest/ivltests/func_empty_arg2.v new file mode 100644 index 000000000..e19bd0ed0 --- /dev/null +++ b/ivtest/ivltests/func_empty_arg2.v @@ -0,0 +1,29 @@ +// Check that it is possible to call functins with empty arguments if they have +// default values. Check that this works if the function call is in a module +// port binding expression. + +module M (input [31:0] x, input [31:0] y); + + initial begin + #1 + if (x === 623 && y == 624) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule + +module test; + + function [31:0] f(reg [31:0] a, reg [31:0] b = 2, reg [31:0] c = 3); + return a * 100 + b * 10 + c; + endfunction + + M i_m ( + .x(f(6, )), + .y(f(6, , 4)) + ); + +endmodule diff --git a/ivtest/ivltests/func_empty_arg3.v b/ivtest/ivltests/func_empty_arg3.v new file mode 100644 index 000000000..8b949a894 --- /dev/null +++ b/ivtest/ivltests/func_empty_arg3.v @@ -0,0 +1,41 @@ +// Check that it is possible to call functins with empty arguments if they have +// default values. Check that this works if the function call is part of a force +// statement in an automatic context. + +module test; + + bit failed = 1'b0; + + `define check(expr, val) \ + if (expr !== val) begin \ + $display("FAILED. %s, expected %d, got %d", `"expr`", val, expr); \ + failed = 1'b1; \ + end + + integer x, y, z, w; + + function automatic integer f(integer a = 1, integer b = 2, integer c = 3); + return a * 100 + b * 10 + c; + endfunction + + task automatic t; + force x = f(4, , 6); + force y = f(4, 5, ); + force z = f(4, , ); + force w = f( , , 6); + endtask + + initial begin + t; + + `check(x, 426); + `check(y, 453); + `check(z, 423); + `check(w, 126); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/func_empty_arg_fail1.v b/ivtest/ivltests/func_empty_arg_fail1.v new file mode 100644 index 000000000..0804438dd --- /dev/null +++ b/ivtest/ivltests/func_empty_arg_fail1.v @@ -0,0 +1,16 @@ +// Check that passing too many empty arguments to a function results in an error. + +module test; + + function f(integer a = 1, integer b = 2, integer c = 3); + return a + 10 * b + 100 * c; + endfunction + + initial begin + integer x; + x = f( , , ,); // This should fail. 4 empty args, even though the function + // only takes 3 args + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/func_empty_arg_fail2.v b/ivtest/ivltests/func_empty_arg_fail2.v new file mode 100644 index 000000000..d197a719b --- /dev/null +++ b/ivtest/ivltests/func_empty_arg_fail2.v @@ -0,0 +1,16 @@ +// Check that passing additional empty arguments to a function results in an error. + +module test; + + function f(integer a = 1, integer b = 2, integer c = 3); + return a + 10 * b + 100 * c; + endfunction + + initial begin + integer x; + x = f(4, 5, 6, ); // This should fail. 4 empty args, even though the function + // only takes 3 args + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/func_empty_arg_fail3.v b/ivtest/ivltests/func_empty_arg_fail3.v new file mode 100644 index 000000000..72480a47d --- /dev/null +++ b/ivtest/ivltests/func_empty_arg_fail3.v @@ -0,0 +1,16 @@ +// Check that passing empty arguments to a function without any ports is an +// error. + +module test; + + function f(); + return 42; + endfunction + + initial begin + integer x; + x = f( , ); // This should fail. The function takes no arguments. + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/func_empty_arg_fail4.v b/ivtest/ivltests/func_empty_arg_fail4.v new file mode 100644 index 000000000..a1ed27c97 --- /dev/null +++ b/ivtest/ivltests/func_empty_arg_fail4.v @@ -0,0 +1,16 @@ +// Check that an error is reported when passing an empty function argument for a +// port without a default value. + +module test; + + function f(integer a, integer b = 2); + return a + 10 * b + 100 * c; + endfunction + + initial begin + integer x; + x = f( , 3); // This should fail. No default value specified. + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 156e76d49..f19cf254f 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -313,6 +313,13 @@ fork_join_any normal,-g2009 ivltests fork_join_dis normal,-g2009 ivltests fork_join_none normal,-g2009 ivltests fr49 normal,-g2009 ivltests +func_empty_arg1 normal,-g2005-sv ivltests +func_empty_arg2 normal,-g2005-sv ivltests +func_empty_arg3 normal,-g2005-sv ivltests +func_empty_arg_fail1 CE,-g2005-sv ivltests +func_empty_arg_fail2 CE,-g2005-sv ivltests +func_empty_arg_fail3 CE,-g2005-sv ivltests +func_empty_arg_fail4 CE,-g2005-sv ivltests func_init_var1 normal,-g2009 ivltests func_init_var2 normal,-g2009 ivltests func_init_var3 normal,-g2009 ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 84e2bd204..76c297b2f 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -82,6 +82,7 @@ automatic_task3 CE ivltests br942 CE ivltests br_gh531 CE ivltests def_nettype CE ivltests +func_empty_arg3 CE,-g2005-sv ivltests func_init_var1 CE,-pallowsigned=1 ivltests func_init_var2 CE,-pallowsigned=1 ivltests func_init_var3 CE,-pallowsigned=1 ivltests