From c9f6bd68b99a7bdd829d5f2da86fab7b3ad3239f Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 3 Jul 2009 15:37:44 -0700 Subject: [PATCH] Add compiler warnings for more constant out of bounds array accesses. This patch adds compiler warning messages for all/most constant out of bounds array access. --- elab_expr.cc | 4 ++++ elab_lval.cc | 26 ++++++++++---------------- elab_net.cc | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index b105f8dda..b40044af5 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -2610,6 +2610,9 @@ NetExpr* PEIdent::elaborate_expr_net_word_(Design*des, NetScope*scope, // Special case: The index is out of range, so the value // of this expression is a 'bx vector the width of a word. if (!net->array_index_is_valid(addr)) { + cerr << get_fileline() << ": warning: returning 'bx for out " + "of bounds array access " << net->name() + << "[" << addr << "]." << endl; NetEConst*resx = make_const_x(net->vector_width()); resx->set_line(*this); delete word_index; @@ -2670,6 +2673,7 @@ NetExpr* PEIdent::elaborate_expr_net_word_(Design*des, NetScope*scope, return elaborate_expr_net_bit_(des, scope, res, found_in); ivl_assert(*this, word_sel == index_component_t::SEL_NONE); + return res; } diff --git a/elab_lval.cc b/elab_lval.cc index 7478eab8c..c421e1243 100644 --- a/elab_lval.cc +++ b/elab_lval.cc @@ -257,13 +257,11 @@ NetAssign_* PEIdent::elaborate_lval_net_word_(Design*des, ivl_assert(*this, index_head.msb != 0); ivl_assert(*this, index_head.lsb == 0); + // These are not used, but they need to have a default value. ivl_variable_type_t expr_type_tmp = IVL_VT_NO_TYPE; - // This not used, but it needs to have a default value. bool unsized_flag_tmp = false; - index_head.msb->test_width(des, scope, - reg->vector_width(), reg->vector_width(), - expr_type_tmp, - unsized_flag_tmp); + index_head.msb->test_width(des, scope, integer_width, integer_width, + expr_type_tmp, unsized_flag_tmp); NetExpr*word = elab_and_eval(des, scope, index_head.msb, -1); @@ -338,16 +336,14 @@ bool PEIdent::elaborate_lval_net_bit_(Design*des, NetNet*reg = lv->sig(); + // These are not used, but they need to have a default value. ivl_variable_type_t expr_type_tmp = IVL_VT_NO_TYPE; - // This not used, but it needs to have a default value. bool unsized_flag_tmp = false; - index_tail.msb->test_width(des, scope, - lv->lwidth(), lv->lwidth(), - expr_type_tmp, - unsized_flag_tmp); + index_tail.msb->test_width(des, scope, integer_width, integer_width, + expr_type_tmp, unsized_flag_tmp); - // Bit selects have a single select expression. Evaluate the + // Bit selects have a single select expression. Evaluate the // constant value and treat it as a part select with a bit // width of 1. NetExpr*mux = elab_and_eval(des, scope, index_tail.msb, -1); @@ -472,13 +468,11 @@ bool PEIdent::elaborate_lval_net_idx_(Design*des, unsigned long wid; calculate_up_do_width_(des, scope, wid); + // These are not used, but they need to have a default value. ivl_variable_type_t expr_type_tmp = IVL_VT_NO_TYPE; - // This not used, but it needs to have a default value. bool unsized_flag_tmp = false; - index_tail.msb->test_width(des, scope, - wid, wid, - expr_type_tmp, - unsized_flag_tmp); + index_tail.msb->test_width(des, scope, integer_width, integer_width, + expr_type_tmp, unsized_flag_tmp); NetExpr*base = elab_and_eval(des, scope, index_tail.msb, -1); diff --git a/elab_net.cc b/elab_net.cc index 719173b69..885bd6ae0 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -423,7 +423,7 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope, // Default part select is the entire word. unsigned midx = sig->vector_width()-1, lidx = 0; // The default word select is the first. - unsigned widx = 0; + long widx = 0; const name_component_t&name_tail = path_.back(); @@ -445,6 +445,12 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope, } ivl_assert(*this, index_head.sel == index_component_t::SEL_BIT); + // These are not used, but they need to have a default value. + ivl_variable_type_t expr_type_tmp = IVL_VT_NO_TYPE; + bool unsized_flag_tmp = false; + index_head.msb->test_width(des, scope, + integer_width, integer_width, + expr_type_tmp, unsized_flag_tmp); need_constant_expr = true; NetExpr*tmp_ex = elab_and_eval(des, scope, index_head.msb, -1); need_constant_expr = false; @@ -520,7 +526,12 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope, unsigned subnet_wid = midx-lidx+1; if (sig->pin_count() > 1) { - assert(widx < sig->pin_count()); + if (widx < 0 || widx >= (long) sig->pin_count()) { + cerr << get_fileline() << ": warning: ignoring out of " + "bounds l-value array access " + << sig->name() << "[" << widx << "]." << endl; + return 0; + } NetNet*tmp = new NetNet(scope, scope->local_symbol(), sig->type(), sig->vector_width());