From 9004d10df44335494eab9f7a3a040be1b877477f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 21 Jun 2026 14:36:14 -0700 Subject: [PATCH 1/2] Handle invalid l-value indexed part select bases The l-value indexed part select path elaborates the base expression with `elab_and_eval()`. If the base expression can not be bound this returns a nullptr, but the l-value path dereferenced it while checking the expression type. For example, `a[does_not_exist -: 2] = 2'b00;` reported the bind error and then crashed. Return early when base elaboration fails. This matches the r-value indexed part select path and leaves the existing bind error as the reported elaboration error. Signed-off-by: Lars-Peter Clausen --- elab_lval.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elab_lval.cc b/elab_lval.cc index 1068954d1..4d14fdb83 100644 --- a/elab_lval.cc +++ b/elab_lval.cc @@ -883,8 +883,10 @@ bool PEIdent::elaborate_lval_net_idx_(Design*des, calculate_up_do_width_(des, scope, wid); NetExpr*base = elab_and_eval(des, scope, index_tail.msb, -1); + if (!base) + return false; - if (base && base->expr_type() == IVL_VT_REAL) { + if (base->expr_type() == IVL_VT_REAL) { cerr << get_fileline() << ": error: Indexed part select base " "expression for "; cerr << lv->sig()->name() << "[" << *base; From 9fb607d98e1b46a68dbfbff60db8d83a5cb31c96 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 21 Jun 2026 14:37:27 -0700 Subject: [PATCH 2/2] Add regression test for indexed part select l-value bases Check that an invalid indexed part select base on a procedural l-value is reported as a normal compile error instead of crashing after the bind error. Signed-off-by: Lars-Peter Clausen --- .../ivltests/sv_lval_idx_part_invalid_base_down_fail.v | 9 +++++++++ ivtest/regress-vvp.list | 1 + .../sv_lval_idx_part_invalid_base_down_fail.json | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 ivtest/ivltests/sv_lval_idx_part_invalid_base_down_fail.v create mode 100644 ivtest/vvp_tests/sv_lval_idx_part_invalid_base_down_fail.json diff --git a/ivtest/ivltests/sv_lval_idx_part_invalid_base_down_fail.v b/ivtest/ivltests/sv_lval_idx_part_invalid_base_down_fail.v new file mode 100644 index 000000000..769a76899 --- /dev/null +++ b/ivtest/ivltests/sv_lval_idx_part_invalid_base_down_fail.v @@ -0,0 +1,9 @@ +// Check that invalid indexed part-select l-value bases report an error. + +module test; + reg [31:0] a; + + initial begin + a[does_not_exist -: 2] = 2'b00; + end +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index b66ada6b5..043df7b52 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -343,6 +343,7 @@ sv_lval_concat_uarray_fail1 vvp_tests/sv_lval_concat_uarray_fail1.json sv_lval_concat_uarray_fail2 vvp_tests/sv_lval_concat_uarray_fail2.json sv_lval_concat_uarray_fail3 vvp_tests/sv_lval_concat_uarray_fail3.json sv_lval_concat_uarray_fail4 vvp_tests/sv_lval_concat_uarray_fail4.json +sv_lval_idx_part_invalid_base_down_fail vvp_tests/sv_lval_idx_part_invalid_base_down_fail.json sv_mixed_assign1 vvp_tests/sv_mixed_assign1.json sv_mixed_assign2 vvp_tests/sv_mixed_assign2.json sv_mixed_assign_error1 vvp_tests/sv_mixed_assign_error1.json diff --git a/ivtest/vvp_tests/sv_lval_idx_part_invalid_base_down_fail.json b/ivtest/vvp_tests/sv_lval_idx_part_invalid_base_down_fail.json new file mode 100644 index 000000000..e04a3a978 --- /dev/null +++ b/ivtest/vvp_tests/sv_lval_idx_part_invalid_base_down_fail.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_lval_idx_part_invalid_base_down_fail.v", + "iverilog-args" : [ "-g2001" ] +}