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.
This commit is contained in:
parent
067fcc07a1
commit
c9f6bd68b9
|
|
@ -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
|
// Special case: The index is out of range, so the value
|
||||||
// of this expression is a 'bx vector the width of a word.
|
// of this expression is a 'bx vector the width of a word.
|
||||||
if (!net->array_index_is_valid(addr)) {
|
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());
|
NetEConst*resx = make_const_x(net->vector_width());
|
||||||
resx->set_line(*this);
|
resx->set_line(*this);
|
||||||
delete word_index;
|
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);
|
return elaborate_expr_net_bit_(des, scope, res, found_in);
|
||||||
|
|
||||||
ivl_assert(*this, word_sel == index_component_t::SEL_NONE);
|
ivl_assert(*this, word_sel == index_component_t::SEL_NONE);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
26
elab_lval.cc
26
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.msb != 0);
|
||||||
ivl_assert(*this, index_head.lsb == 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;
|
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;
|
bool unsized_flag_tmp = false;
|
||||||
index_head.msb->test_width(des, scope,
|
index_head.msb->test_width(des, scope, integer_width, integer_width,
|
||||||
reg->vector_width(), reg->vector_width(),
|
expr_type_tmp, unsized_flag_tmp);
|
||||||
expr_type_tmp,
|
|
||||||
unsized_flag_tmp);
|
|
||||||
|
|
||||||
NetExpr*word = elab_and_eval(des, scope, index_head.msb, -1);
|
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();
|
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;
|
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;
|
bool unsized_flag_tmp = false;
|
||||||
index_tail.msb->test_width(des, scope,
|
index_tail.msb->test_width(des, scope, integer_width, integer_width,
|
||||||
lv->lwidth(), lv->lwidth(),
|
expr_type_tmp, unsized_flag_tmp);
|
||||||
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
|
// constant value and treat it as a part select with a bit
|
||||||
// width of 1.
|
// width of 1.
|
||||||
NetExpr*mux = elab_and_eval(des, scope, index_tail.msb, -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;
|
unsigned long wid;
|
||||||
calculate_up_do_width_(des, scope, 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;
|
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;
|
bool unsized_flag_tmp = false;
|
||||||
index_tail.msb->test_width(des, scope,
|
index_tail.msb->test_width(des, scope, integer_width, integer_width,
|
||||||
wid, wid,
|
expr_type_tmp, unsized_flag_tmp);
|
||||||
expr_type_tmp,
|
|
||||||
unsized_flag_tmp);
|
|
||||||
|
|
||||||
NetExpr*base = elab_and_eval(des, scope, index_tail.msb, -1);
|
NetExpr*base = elab_and_eval(des, scope, index_tail.msb, -1);
|
||||||
|
|
||||||
|
|
|
||||||
15
elab_net.cc
15
elab_net.cc
|
|
@ -423,7 +423,7 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope,
|
||||||
// Default part select is the entire word.
|
// Default part select is the entire word.
|
||||||
unsigned midx = sig->vector_width()-1, lidx = 0;
|
unsigned midx = sig->vector_width()-1, lidx = 0;
|
||||||
// The default word select is the first.
|
// The default word select is the first.
|
||||||
unsigned widx = 0;
|
long widx = 0;
|
||||||
|
|
||||||
const name_component_t&name_tail = path_.back();
|
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);
|
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;
|
need_constant_expr = true;
|
||||||
NetExpr*tmp_ex = elab_and_eval(des, scope, index_head.msb, -1);
|
NetExpr*tmp_ex = elab_and_eval(des, scope, index_head.msb, -1);
|
||||||
need_constant_expr = false;
|
need_constant_expr = false;
|
||||||
|
|
@ -520,7 +526,12 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope,
|
||||||
unsigned subnet_wid = midx-lidx+1;
|
unsigned subnet_wid = midx-lidx+1;
|
||||||
|
|
||||||
if (sig->pin_count() > 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(),
|
NetNet*tmp = new NetNet(scope, scope->local_symbol(),
|
||||||
sig->type(), sig->vector_width());
|
sig->type(), sig->vector_width());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue