Add error on illegal enum base type (#3010).

This commit is contained in:
Wilson Snyder 2024-11-05 00:58:46 -05:00
parent b1dfdef0a9
commit 753ea29df8
6 changed files with 54 additions and 9 deletions

View File

@ -13,8 +13,9 @@ Verilator 5.031 devel
**Minor:**
* Add coverage point hierarchy to coverage reports (#5575) (#5576). [Andrew Nolte]
* Add error on illegal enum base type (#3010). [Iztok Jeras]
* Add error when improperly storing to parameter (#5147). [Gökçe Aydos]
* Add coverage point hierarchy to coverage reports (#5575) (#5576). [Andrew Nolte]
* Fix can't locate scope error in interface task delayed assignment (#5462) (#5568). [Zhou Shen]
* Fix BLKANDNBLK for for VARXREFs (#5569). [Todd Strader]
* Fix VPI error instead of fatal for vpi_get_value() on large signals (#5571). [Todd Strader]

View File

@ -2346,6 +2346,13 @@ class WidthVisitor final : public VNVisitor {
UINFO(5, " ENUMDTYPE " << nodep << endl);
nodep->refDTypep(iterateEditMoveDTypep(nodep, nodep->subDTypep()));
nodep->dtypep(nodep);
AstBasicDType* basicp = nodep->dtypep()->skipRefp()->basicp();
if (!basicp || !basicp->keyword().isIntNumeric()) {
nodep->v3error(
"Enum type must be an integer atom or vector type (IEEE 1800-2023 6.19)");
basicp = nodep->findSigned32DType()->basicp();
nodep->refDTypep(basicp);
}
nodep->widthFromSub(nodep->subDTypep());
// Assign widths
userIterateAndNext(nodep->itemsp(), WidthVP{nodep->dtypep(), BOTH}.p());
@ -2376,17 +2383,11 @@ class WidthVisitor final : public VNVisitor {
itemp->v3error("Enum value that is unassigned cannot follow value with X/Zs "
"(IEEE 1800-2023 6.19)");
}
if (!nodep->dtypep()->basicp()
&& !nodep->dtypep()->basicp()->keyword().isIntNumeric()) {
itemp->v3error("Enum names without values only allowed on numeric types");
// as can't +1 to resolve them.
}
itemp->valuep(new AstConst{itemp->fileline(), num});
}
const AstConst* const constp = VN_AS(itemp->valuep(), Const);
if (constp->num().isFourState() && nodep->dtypep()->basicp()
&& !nodep->dtypep()->basicp()->isFourstate()) {
if (constp->num().isFourState() && basicp->basicp() && !basicp->isFourstate()) {
itemp->v3error("Enum value with X/Zs cannot be assigned to non-fourstate type "
"(IEEE 1800-2023 6.19)");
}

View File

@ -20,7 +20,6 @@ Suppressed = {}
for s in [
' exited with ', # Is hit; driver.py filters out
'EOF in unterminated string', # Instead get normal unterminated
'Enum names without values only allowed on numeric types', # Hard to hit
'Enum ranges must be integral, per spec', # Hard to hit
'Import package not found: ', # Errors earlier, until future parser released
'Return with return value isn\'t underneath a function', # Hard to hit, get other bad return messages

View File

@ -0,0 +1,5 @@
%Error: t/t_enum_base_bad.v:13:12: Enum type must be an integer atom or vector type (IEEE 1800-2023 6.19)
: ... note: In instance 't'
13 | typedef enum s_t {
| ^~~~
%Error: Exiting due to

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('linter')
test.lint(fails=True, expect_filename=test.golden_filename)
test.passes()

View File

@ -0,0 +1,23 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t(/*AUTOARG*/);
typedef struct {
int a;
} s_t;
typedef enum s_t {
EN_ZERO } bad_t;
typedef int int_t;
typedef enum int_t { EN_ONE = 1 } ok1_t;
s_t s;
int_t i;
endmodule