diff --git a/Changes b/Changes index 40b9b157e..de3482830 100644 --- a/Changes +++ b/Changes @@ -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] diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 1f7c25235..dbceb2b82 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -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)"); } diff --git a/test_regress/t/t_dist_warn_coverage.py b/test_regress/t/t_dist_warn_coverage.py index 3ad81cedc..e953e0217 100755 --- a/test_regress/t/t_dist_warn_coverage.py +++ b/test_regress/t/t_dist_warn_coverage.py @@ -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 diff --git a/test_regress/t/t_enum_base_bad.out b/test_regress/t/t_enum_base_bad.out new file mode 100644 index 000000000..74839d10a --- /dev/null +++ b/test_regress/t/t_enum_base_bad.out @@ -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 diff --git a/test_regress/t/t_enum_base_bad.py b/test_regress/t/t_enum_base_bad.py new file mode 100755 index 000000000..31228c9a7 --- /dev/null +++ b/test_regress/t/t_enum_base_bad.py @@ -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() diff --git a/test_regress/t/t_enum_base_bad.v b/test_regress/t/t_enum_base_bad.v new file mode 100644 index 000000000..2647b47e8 --- /dev/null +++ b/test_regress/t/t_enum_base_bad.v @@ -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