Handle invalid packed dimensions
Trying to elaborate a type with invalid packed dimensions currently results in a crash. E.g. `typedef logic [] T;` The issue is in the `elaborate_array_ranges()` function which does not verify that the range specification is valid. Replace the `elaborate_array_ranges()` with `evaluate_ranges()`, which does the same thing, but properly checks the range specification and reports an error if it is invalid. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
f705e7b61c
commit
52925ce9ff
44
elab_type.cc
44
elab_type.cc
|
|
@ -34,44 +34,6 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/*
|
|
||||||
* Some types have a list of ranges that need to be elaborated. This
|
|
||||||
* function elaborates the ranges referenced by "dims" into the vector
|
|
||||||
* "ranges".
|
|
||||||
*/
|
|
||||||
static void elaborate_array_ranges(Design*des, NetScope*scope,
|
|
||||||
vector<netrange_t>&ranges,
|
|
||||||
const list<pform_range_t>*dims)
|
|
||||||
{
|
|
||||||
if (dims == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (list<pform_range_t>::const_iterator cur = dims->begin()
|
|
||||||
; cur != dims->end() ; ++ cur) {
|
|
||||||
|
|
||||||
NetExpr*me = elab_and_eval(des, scope, cur->first, 0, true);
|
|
||||||
|
|
||||||
NetExpr*le = elab_and_eval(des, scope, cur->second, 0, true);
|
|
||||||
|
|
||||||
/* If elaboration failed for either expression, we
|
|
||||||
should have already reported the error, so just
|
|
||||||
skip the following evaluation to recover. */
|
|
||||||
|
|
||||||
long mnum = 0, lnum = 0;
|
|
||||||
if ( me && ! eval_as_long(mnum, me) ) {
|
|
||||||
assert(0);
|
|
||||||
des->errors += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( le && ! eval_as_long(lnum, le) ) {
|
|
||||||
assert(0);
|
|
||||||
des->errors += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ranges.push_back(netrange_t(mnum, lnum));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Elaborations of types may vary depending on the scope that it is
|
* Elaborations of types may vary depending on the scope that it is
|
||||||
* done in, so keep a per-scope cache of the results.
|
* done in, so keep a per-scope cache of the results.
|
||||||
|
|
@ -164,7 +126,8 @@ ivl_type_s* enum_type_t::elaborate_type_raw(Design*, NetScope*scope) const
|
||||||
ivl_type_s* vector_type_t::elaborate_type_raw(Design*des, NetScope*scope) const
|
ivl_type_s* vector_type_t::elaborate_type_raw(Design*des, NetScope*scope) const
|
||||||
{
|
{
|
||||||
vector<netrange_t> packed;
|
vector<netrange_t> packed;
|
||||||
elaborate_array_ranges(des, scope, packed, pdims.get());
|
if (pdims.get())
|
||||||
|
evaluate_ranges(des, scope, this, packed, *pdims);
|
||||||
|
|
||||||
netvector_t*tmp = new netvector_t(packed, base_type);
|
netvector_t*tmp = new netvector_t(packed, base_type);
|
||||||
tmp->set_signed(signed_flag);
|
tmp->set_signed(signed_flag);
|
||||||
|
|
@ -192,7 +155,8 @@ ivl_type_s* string_type_t::elaborate_type_raw(Design*, NetScope*) const
|
||||||
ivl_type_s* parray_type_t::elaborate_type_raw(Design*des, NetScope*scope) const
|
ivl_type_s* parray_type_t::elaborate_type_raw(Design*des, NetScope*scope) const
|
||||||
{
|
{
|
||||||
vector<netrange_t>packed;
|
vector<netrange_t>packed;
|
||||||
elaborate_array_ranges(des, scope, packed, dims.get());
|
if (dims.get())
|
||||||
|
evaluate_ranges(des, scope, this, packed, *dims);
|
||||||
|
|
||||||
ivl_type_t etype = base_type->elaborate_type(des, scope);
|
ivl_type_t etype = base_type->elaborate_type(des, scope);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue