netenum_t: Fix line info

enum_type_t inherits from LineInfo, but also has a LineInfo field called
`li`.

When a enum_type_t is created the LineInfo of the object itself is set to
the location where the type is declared.

The `li` field gets set when a signal of the enum_type_t is created to the
location where the signal is created. The `li` field is then used when
elaborating a netenum_t to set the line information on the netenum_t.

This works fine when the enum is directly used to declare a signal, since
the location of the type and signal declaration are the same and there is
only one signal of that type.

But when using a typedef and declaring multiple signals with the same type
the `li` field will be repeatedly set and eventually point to the last
signal declaration of that type.

On the other hand when using or declaring an enum as part of an aggregate
type such as an array, struct or class the line info will never be
set.

This can cause misleading error messages. E.g.

```
typedef enum {
  A, B = A
} e_t;

struct packed {
  e_t e;
} s;
```

will generate

```
:0: error: Enumeration name B and A have the same value: 32'sd0
```

To fix this use the LineInfo that was assigned to the enum_type_t itself
when it was declared and remove the `li` field.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-01-09 21:21:55 +01:00
parent ac815a6118
commit 057cd700fe
3 changed files with 1 additions and 5 deletions

View File

@ -203,7 +203,7 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
enum_type->names->size(),
enum_type);
use_enum->set_line(enum_type->li);
use_enum->set_line(*enum_type);
scope->add_enumeration_set(enum_type, use_enum);
size_t name_idx = 0;

View File

@ -3588,9 +3588,6 @@ static void pform_set_enum(const struct vlltype&li, enum_type_t*enum_type,
// IVL_VT_BOOL.
assert(enum_type->base_type==IVL_VT_LOGIC || enum_type->base_type==IVL_VT_BOOL);
// Add the file and line information to the enumeration type.
FILE_NAME(&(enum_type->li), li);
// Now apply the checked enumeration type to the variables
// that are being declared with this type.
for (list<perm_string>::iterator cur = names->begin()

View File

@ -191,7 +191,6 @@ struct enum_type_t : public data_type_t {
bool integer_flag; // True if "integer" was used
std::unique_ptr< std::list<pform_range_t> > range;
std::unique_ptr< std::list<named_pexpr_t> > names;
LineInfo li;
};
struct struct_member_t : public LineInfo {