From 12188f8d8380abab6b4abaa580273eab39bc8efc Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 17 May 2022 11:04:25 +0200 Subject: [PATCH] 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 --- ivtest/ivltests/assign_op_oob.v | 44 +++++++++++++++++++++++++++++++++ ivtest/regress-sv.list | 1 + ivtest/regress-vlog95.list | 1 + 3 files changed, 46 insertions(+) create mode 100644 ivtest/ivltests/assign_op_oob.v diff --git a/ivtest/ivltests/assign_op_oob.v b/ivtest/ivltests/assign_op_oob.v new file mode 100644 index 000000000..14897d930 --- /dev/null +++ b/ivtest/ivltests/assign_op_oob.v @@ -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 diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 6c3afca56..bcc4f0047 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -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 diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index bde6fa422..5886acce3 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -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