From eaea5e7939c44f920d8e147864a96cfb8d1b0ed6 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 2 Oct 2022 21:28:28 +0200 Subject: [PATCH] Print error if foreach loops variables exceed number of array dimensions Currently when the number of loop variables in a foreach loop is larger than the number of array dimensions an assertion is triggered. Turn this into a error message instead for graceful error reporting. Signed-off-by: Lars-Peter Clausen --- elaborate.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/elaborate.cc b/elaborate.cc index 6e9cc3cdc..1ea15f452 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -5380,7 +5380,6 @@ NetProc* PForeach::elaborate_static_array_(Design*des, NetScope*scope, } ivl_assert(*this, index_vars_.size() > 0); - ivl_assert(*this, dims.size() >= index_vars_.size()); NetProc*sub; if (statement_) @@ -5389,6 +5388,15 @@ NetProc* PForeach::elaborate_static_array_(Design*des, NetScope*scope, sub = new NetBlock(NetBlock::SEQU, 0); NetForLoop*stmt = 0; + if (index_vars_.size() > dims.size()) { + delete sub; + cerr << get_fileline() << ": error: Number of foreach loop indices" + << "(" << index_vars_.size() << ") must not exceed number of " + << "array dimensions (" << dims.size() << ")." << endl; + des->errors++; + return nullptr; + } + for (int idx_idx = index_vars_.size()-1 ; idx_idx >= 0 ; idx_idx -= 1) { const netrange_t&idx_range = dims[idx_idx];