Add regression test for out-of-bounds array assignment operator

Check that an assignment operator on an out-of-bounds array element works
as expected. The out-of-bounds access should leave the array unmodified,
but the right-hand side must be evaluated regardless.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-05-17 11:04:25 +02:00
parent d651aefd92
commit 12188f8d83
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,44 @@
// Check that the assignment operator is supported for out-of-bounds indices.
// The write should be skipped, but side effects of the right-hand side
// expression should still get evaluated.
module test;
// Check that wider than 32 works
logic [39:0] a[1:0];
integer i;
logic [39:0] j = 0;
function logic [39:0] f;
j++;
return j;
endfunction
initial begin
a[0] = 23;
a[1] = 42;
// Immediate out-of-bounds indices
a[-1] += f();
a[2] += f();
a['hx] += f();
// Variable out-of-bounds indices
i = -1;
a[i] += f();
i = 2;
a[i] += f();
i = 'hx;
a[i] += f();
// Check that the in-bounds elements do not get affected by out-of-bounds
// updates. Check that the left-hand side of the operator assignment gets
// evaluated.
if (a[0] == 23 && a[1] == 42 && j == 6) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -99,6 +99,7 @@ array_packed normal,-g2005-sv ivltests
assign_op_after_cmp1 normal,-g2009 ivltests
assign_op_after_cmp2 normal,-g2009 ivltests
assign_op_concat normal,-g2009 ivltests
assign_op_oob normal,-g2009 ivltests
assign_op_type normal,-g2009 ivltests
bitp1 normal,-g2005-sv ivltests
bits normal,-g2005-sv ivltests

View File

@ -792,6 +792,7 @@ writemem-invalid RE ivltests gold=writemem-invalid-vlog95.gold
# For Verilog 95 signed is supported as an option (-pallowsigned=1).
array6 normal,-pallowsigned=1 ivltests
assign_op_oob normal,-g2009,-pallowsigned=1 ivltests
assign_op_type normal,-g2009,-pallowsigned=1 ivltests
bitp1 normal,-g2009,-pallowsigned=1 ivltests
bits normal,-g2009,-pallowsigned=1 ivltests