From 054b792021f7e256615724d00b7b74fbe9da9059 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 27 Nov 2022 08:44:30 -0500 Subject: [PATCH] Fix ENUMVALUE error to show value location (#3783) --- src/V3Width.cpp | 17 +++++++++-------- test_regress/t/t_enum_type_bad.out | 18 +++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/V3Width.cpp b/src/V3Width.cpp index d5cf3d5f2..c99f2368e 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -6149,14 +6149,15 @@ private: = VN_CAST(expDTypep->skipRefToEnump(), EnumDType)) { const auto castable = computeCastable(expEnump, underp->dtypep(), underp); if (castable != COMPATIBLE && castable != ENUM_IMPLICIT && !VN_IS(underp, Cast) - && !VN_IS(underp, CastDynamic) && !m_enumItemp && warnOn) { - nodep->v3warn(ENUMVALUE, - "Implicit conversion to enum " - << expDTypep->prettyDTypeNameQ() << " from " - << underp->dtypep()->prettyDTypeNameQ() - << " (IEEE 1800-2017 6.19.3)\n" - << nodep->warnMore() - << "... Suggest use enum's mnemonic, or static cast"); + && !VN_IS(underp, CastDynamic) && !m_enumItemp + && !nodep->fileline()->warnIsOff(V3ErrorCode::ENUMVALUE) && warnOn) { + underp->v3warn(ENUMVALUE, + "Implicit conversion to enum " + << expDTypep->prettyDTypeNameQ() << " from " + << underp->dtypep()->prettyDTypeNameQ() + << " (IEEE 1800-2017 6.19.3)\n" + << nodep->warnMore() + << "... Suggest use enum's mnemonic, or static cast"); if (debug()) nodep->backp()->dumpTree("- back: "); } } diff --git a/test_regress/t/t_enum_type_bad.out b/test_regress/t/t_enum_type_bad.out index 2d782732e..59d5cb988 100644 --- a/test_regress/t/t_enum_type_bad.out +++ b/test_regress/t/t_enum_type_bad.out @@ -1,17 +1,17 @@ -%Error-ENUMVALUE: t/t_enum_type_bad.v:28:9: Implicit conversion to enum 't.e_t' from 'logic[31:0]' (IEEE 1800-2017 6.19.3) - : ... In instance t +%Error-ENUMVALUE: t/t_enum_type_bad.v:28:11: Implicit conversion to enum 't.e_t' from 'logic[31:0]' (IEEE 1800-2017 6.19.3) + : ... In instance t : ... Suggest use enum's mnemonic, or static cast 28 | e = 1; - | ^ + | ^ ... For error description see https://verilator.org/warn/ENUMVALUE?v=latest -%Error-ENUMVALUE: t/t_enum_type_bad.v:29:9: Implicit conversion to enum 't.o_t' from 't.e_t' (IEEE 1800-2017 6.19.3) - : ... In instance t +%Error-ENUMVALUE: t/t_enum_type_bad.v:29:11: Implicit conversion to enum 't.o_t' from 't.e_t' (IEEE 1800-2017 6.19.3) + : ... In instance t : ... Suggest use enum's mnemonic, or static cast 29 | o = e; - | ^ -%Error-ENUMVALUE: t/t_enum_type_bad.v:35:9: Implicit conversion to enum 't.o_t' from 'ENUMDTYPE 't.e_t'' (IEEE 1800-2017 6.19.3) - : ... In instance t + | ^ +%Error-ENUMVALUE: t/t_enum_type_bad.v:35:15: Implicit conversion to enum 't.o_t' from 'ENUMDTYPE 't.e_t'' (IEEE 1800-2017 6.19.3) + : ... In instance t : ... Suggest use enum's mnemonic, or static cast 35 | o = str.m_e; - | ^ + | ^~~ %Error: Exiting due to