Check that packed array base-type is packed

When creating a signal of a packed array it is checked that the base-type
of the packed array is a packed type.

But this check is only done if the packed array itself is the type of the
signal. Placing the packed array in a struct or class will elaborate fine,
but then crash during simulation.

E.g.

```
typedef real myreal;
struct packed {
  myreal [1:0] p;
} s;
```

Move the check from signal creation to type elaboration, so that it is not
possible to create a packed type with a non-packed base-type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-01-09 19:58:20 +01:00
parent adf64f3cc8
commit 9ec42b1b8c
2 changed files with 12 additions and 3 deletions

View File

@ -158,6 +158,18 @@ ivl_type_s* parray_type_t::elaborate_type_raw(Design*des, NetScope*scope) const
if (dims.get())
evaluate_ranges(des, scope, this, packed, *dims);
if (base_type->figure_packed_base_type() == IVL_VT_NO_TYPE) {
cerr << this->get_fileline() << " error: Packed array ";
if (!name.nil())
cerr << "`" << name << "` ";
cerr << "base-type `";
if (base_type->name.nil())
cerr << *base_type;
else
cerr << base_type->name;
cerr << "` is not packed." << endl;
des->errors++;
}
ivl_type_t etype = base_type->elaborate_type(des, scope);
return new netparray_t(packed, etype);

View File

@ -3549,9 +3549,6 @@ static void pform_set_integer_2atom(const struct vlltype&li, uint64_t width, boo
template <class T> static void pform_set2_data_type(const struct vlltype&li, T*data_type, perm_string name, NetNet::Type net_type, list<named_pexpr_t>*attr)
{
ivl_variable_type_t base_type = data_type->figure_packed_base_type();
if (base_type == IVL_VT_NO_TYPE) {
VLerror(li, "Compound type is not PACKED in this context.");
}
PWire*net = pform_get_make_wire_in_scope(li, name, net_type, NetNet::NOT_A_PORT, base_type);
assert(net);