From 393c7a3b498b3bc4c95a67693367668401451da5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 15 Apr 2022 18:44:12 +0200 Subject: [PATCH] Add a regression test for functions with queue return type Check that a queue type is supported for the return type of a function. Make sure that the queue is not cleared in between invocations for non-automatic functions. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_queue_function.v | 41 +++++++++++++++++++++++++++++ ivtest/regress-sv.list | 1 + ivtest/regress-vlog95.list | 1 + 3 files changed, 43 insertions(+) create mode 100644 ivtest/ivltests/sv_queue_function.v diff --git a/ivtest/ivltests/sv_queue_function.v b/ivtest/ivltests/sv_queue_function.v new file mode 100644 index 000000000..9fb52f1eb --- /dev/null +++ b/ivtest/ivltests/sv_queue_function.v @@ -0,0 +1,41 @@ +// Check that a queue return type is supported for functions + +module test; + + typedef int Q[$]; + + // Since this is not an automatic function calling this repeatetly will + // append to the same queue. + function Q f1(int x); + f1.push_back(1 + x); + f1.push_back(2 + x); + endfunction + + // Since this function is automatic a new queue will be created each time it + // is called. + function automatic Q f2(int x); + f2.push_back(1 + x); + f2.push_back(2 + x); + endfunction + + initial begin + Q a, b, c, d; + + a = f1(0); + // `a` should be a copy and not affected by the second call + b = f1(2); + + c = f2(0); + d = f2(2); + + if (a.size() == 2 && a[0] == 1 && a[1] == 2 && + b.size() == 4 && b[0] == 1 && b[1] == 2 && b[2] == 3 && b[3] == 4 && + c.size() == 2 && c[0] == 1 && c[1] == 2 && + d.size() == 2 && d[0] == 3 && d[1] == 4) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index e0503d23c..06b392d6e 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -575,6 +575,7 @@ sv_port_default14 CE,-g2009 ivltests sv_queue1 normal,-g2009 ivltests sv_queue2 normal,-g2009 ivltests sv_queue3 normal,-g2009 ivltests +sv_queue_function normal,-g2009 ivltests sv_queue_parray normal,-g2009,-pfileline=1 ivltests gold=sv_queue_parray.gold sv_queue_parray_bounded normal,-g2009,-pfileline=1 ivltests gold=sv_queue_parray_bounded.gold sv_queue_parray_fail CE,-g2009 ivltests gold=sv_queue_parray_fail.gold diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 7aa9989e8..3f9b3d29b 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -463,6 +463,7 @@ pr3390385b CE,-g2009 ivltests # ++ pr3390385c CE,-g2009 ivltests # ++ pr3390385d CE,-g2009 ivltests # ++ pr3462145 CE,-g2009 ivltests # ++ +sv_queue_function CE,-g2009,-pallowsigned=1 ivltests # queue sv_typedef_darray_base1 CE,-g2009 ivltests # Dyanmic array sv_typedef_darray_base2 CE,-g2009 ivltests # Dyanmic array sv_typedef_darray_base3 CE,-g2009 ivltests # Dyanmic array