From 301a7e587bcb5670644c536d3e69b53e4fa0cb6f Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 25 Apr 2015 22:57:14 +0100 Subject: [PATCH] Fix for GitHub issue #62 - assertion failure on too many array/vector indices. Provide an error message for invalid code that contains more indices than there are dimensions. --- elab_expr.cc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index 33e28bbd6..e309f6162 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -2877,6 +2877,25 @@ NetExpr* PEFNumber::elaborate_expr(Design*, NetScope*, unsigned, unsigned) const bool PEIdent::calculate_packed_indices_(Design*des, NetScope*scope, NetNet*net, list&prefix_indices) const { + unsigned dimensions = net->unpacked_dimensions() + net->packed_dimensions(); + switch (net->data_type()) { + case IVL_VT_STRING: + case IVL_VT_DARRAY: + case IVL_VT_QUEUE: + dimensions += 1; + default: + break; + } + if (path_.back().index.size() > dimensions) { + cerr << get_fileline() << ": error: the number of indices (" + << path_.back().index.size() + << ") is greater than the number of dimensions (" + << dimensions + << ")." << endl; + des->errors += 1; + return false; + } + list index; index = path_.back().index; ivl_assert(*this, index.size() >= net->unpacked_dimensions()); @@ -4633,7 +4652,8 @@ NetExpr* PEIdent::elaborate_expr_net_part_(Design*des, NetScope*scope, { list prefix_indices; bool rc = calculate_packed_indices_(des, scope, net->sig(), prefix_indices); - ivl_assert(*this, rc); + if (!rc) + return 0; long msv, lsv; bool parts_defined_flag; @@ -4773,7 +4793,8 @@ NetExpr* PEIdent::elaborate_expr_net_idx_up_(Design*des, NetScope*scope, { listprefix_indices; bool rc = calculate_packed_indices_(des, scope, net->sig(), prefix_indices); - ivl_assert(*this, rc); + if (!rc) + return 0; NetExpr*base = calculate_up_do_base_(des, scope, need_const); @@ -4875,7 +4896,8 @@ NetExpr* PEIdent::elaborate_expr_net_idx_do_(Design*des, NetScope*scope, { listprefix_indices; bool rc = calculate_packed_indices_(des, scope, net->sig(), prefix_indices); - ivl_assert(*this, rc); + if (!rc) + return 0; NetExpr*base = calculate_up_do_base_(des, scope, need_const); @@ -4963,7 +4985,8 @@ NetExpr* PEIdent::elaborate_expr_net_bit_(Design*des, NetScope*scope, { listprefix_indices; bool rc = calculate_packed_indices_(des, scope, net->sig(), prefix_indices); - ivl_assert(*this, rc); + if (!rc) + return 0; const name_component_t&name_tail = path_.back(); ivl_assert(*this, !name_tail.index.empty());