From ba74c7b5ad49e36440d45383559c1152a1a56095 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 10 May 2026 21:21:32 -0700 Subject: [PATCH 1/2] Reject `real` array indices Array indices must be integral expressions. Using a real valued expression as an unpacked array index currently reaches the vvp real expression code and triggers an assert. Packed bit and part select indices already report an elaboration error for real expressions since commit 2249d224deaa ("Bit/part selects cannot have real index expressions"). Do the same for unpacked array indices. Signed-off-by: Lars-Peter Clausen --- netmisc.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/netmisc.cc b/netmisc.cc index 9e4162800..66e852820 100644 --- a/netmisc.cc +++ b/netmisc.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2025 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2026 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -509,8 +509,15 @@ void indices_to_expressions(Design*des, NetScope*scope, NetExpr*word_index = elab_and_eval(des, scope, cur->msb, -1, need_const); - if (word_index == 0) + if (!word_index) { flags.invalid = true; + } else if (word_index->expr_type() == IVL_VT_REAL) { + cerr << cur->msb->get_fileline() << ": error: " + << "Array index expression cannot be a real value." + << endl; + des->errors += 1; + flags.invalid = true; + } // Track if we detect any non-constant expressions // here. This may allow for a special case. From ea57b6dd9ac8b8563498ce69c10471e76ae81403 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 10 May 2026 22:12:36 -0700 Subject: [PATCH 2/2] Add regression test for real array index error Check that using a real valued expression as an array index is rejected during elaboration. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/array_index_real_fail.v | 12 ++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/array_index_real_fail.json | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 ivtest/ivltests/array_index_real_fail.v create mode 100644 ivtest/vvp_tests/array_index_real_fail.json diff --git a/ivtest/ivltests/array_index_real_fail.v b/ivtest/ivltests/array_index_real_fail.v new file mode 100644 index 000000000..763e24ee9 --- /dev/null +++ b/ivtest/ivltests/array_index_real_fail.v @@ -0,0 +1,12 @@ +// Check that real expressions can not be used as array indices. + +module test; + + reg [1:0] a[1:0]; + real r; + + initial begin + a[r] = 2'b10; + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index e9c9a1633..13b3a3bf8 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -6,6 +6,7 @@ always4A vvp_tests/always4A.json always4B vvp_tests/always4B.json analog1 vvp_tests/analog1.json analog2 vvp_tests/analog2.json +array_index_real_fail vvp_tests/array_index_real_fail.json array_packed_sysfunct vvp_tests/array_packed_sysfunct.json array_packed_value_list vvp_tests/array_packed_value_list.json array_packed_write_read vvp_tests/array_packed_write_read.json diff --git a/ivtest/vvp_tests/array_index_real_fail.json b/ivtest/vvp_tests/array_index_real_fail.json new file mode 100644 index 000000000..a4b453e0a --- /dev/null +++ b/ivtest/vvp_tests/array_index_real_fail.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "array_index_real_fail.v" +}