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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-04-15 18:44:12 +02:00
parent 27f3fcc5f1
commit 393c7a3b49
3 changed files with 43 additions and 0 deletions

View File

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

View File

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

View File

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