From d1656712257ed73552a110bc284c695b6b82dd38 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 28 Nov 2024 14:09:06 -0500 Subject: [PATCH] Improve error when no parameter type value (#5645 partial) --- src/V3Param.cpp | 15 ++++++++++++--- test_regress/t/t_class_param_bad2.out | 6 +++++- test_regress/t/t_class_param_noinit_bad.out | 9 +++++++-- test_regress/t/t_class_param_noinit_bad.v | 2 +- .../t/t_lint_iface_array_topmodule_bad.out | 2 +- test_regress/t/t_lint_iface_topmodule_bad.out | 2 +- test_regress/t/t_param_default_bad.out | 2 +- test_regress/t/t_param_default_presv_bad.out | 2 +- test_regress/t/t_param_noval_bad.out | 8 ++++++-- test_regress/t/t_param_noval_bad.v | 2 +- 10 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/V3Param.cpp b/src/V3Param.cpp index fe580f853..d427c4f58 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -924,13 +924,15 @@ class ParamProcessor final { for (auto* stmtp = srcModpr->stmtsp(); stmtp; stmtp = stmtp->nextp()) { if (AstParamTypeDType* dtypep = VN_CAST(stmtp, ParamTypeDType)) { if (VN_IS(dtypep->subDTypep(), VoidDType)) { - nodep->v3error("Missing type parameter: " << dtypep->prettyNameQ()); + nodep->v3error( + "Class parameter type without default value is never given value" + << " (IEEE 1800-2023 6.20.1): " << dtypep->prettyNameQ()); VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep); } } if (AstVar* const varp = VN_CAST(stmtp, Var)) { if (VN_IS(srcModpr, Class) && varp->isParam() && !varp->valuep()) { - nodep->v3error("Class parameter without initial value is never given value" + nodep->v3error("Class parameter without default value is never given value" << " (IEEE 1800-2023 6.20.1): " << varp->prettyNameQ()); } } @@ -1200,13 +1202,20 @@ class ParamVisitor final : public VNVisitor { iterateChildren(nodep); if (nodep->isParam()) { if (!nodep->valuep() && !VN_IS(m_modp, Class)) { - nodep->v3error("Parameter without initial value is never given value" + nodep->v3error("Parameter without default value is never given value" << " (IEEE 1800-2023 6.20.1): " << nodep->prettyNameQ()); } else { V3Const::constifyParamsEdit(nodep); // The variable, not just the var->init() } } } + void visit(AstParamTypeDType* nodep) override { + iterateChildren(nodep); + if (VN_IS(nodep->subDTypep(), VoidDType)) { + nodep->v3error("Parameter type without default value is never given value" + << " (IEEE 1800-2023 6.20.1): " << nodep->prettyNameQ()); + } + } // Make sure varrefs cause vars to constify before things above void visit(AstVarRef* nodep) override { // Might jump across functions, so beware if ever add a m_funcp diff --git a/test_regress/t/t_class_param_bad2.out b/test_regress/t/t_class_param_bad2.out index 1eadc4902..6def63ba0 100644 --- a/test_regress/t/t_class_param_bad2.out +++ b/test_regress/t/t_class_param_bad2.out @@ -1,5 +1,9 @@ -%Error: t/t_class_param_bad2.v:12:4: Missing type parameter: 'PARAMB' +%Error: t/t_class_param_bad2.v:12:4: Class parameter type without default value is never given value (IEEE 1800-2023 6.20.1): 'PARAMB' : ... note: In instance 't' 12 | Cls c; | ^~~ +%Error: t/t_class_param_bad2.v:7:18: Parameter type without default value is never given value (IEEE 1800-2023 6.20.1): 'PARAMB' + : ... note: In instance 't' + 7 | class Cls #(type PARAMB); + | ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_class_param_noinit_bad.out b/test_regress/t/t_class_param_noinit_bad.out index 3495bc6aa..c3e85d2f3 100644 --- a/test_regress/t/t_class_param_noinit_bad.out +++ b/test_regress/t/t_class_param_noinit_bad.out @@ -1,5 +1,10 @@ -%Error: t/t_class_param_noinit_bad.v:13:7: Class parameter without initial value is never given value (IEEE 1800-2023 6.20.1): 'B' +%Error: t/t_class_param_noinit_bad.v:13:7: Class parameter without default value is never given value (IEEE 1800-2023 6.20.1): 'B' : ... note: In instance 't' 13 | Cls #(1) c; | ^~~ -%Error: Exiting due to +%Error: t/t_class_param_noinit_bad.v:13:7: Class parameter type without default value is never given value (IEEE 1800-2023 6.20.1): 'T' + : ... note: In instance 't' + 13 | Cls #(1) c; + | ^~~ +%Error: Verilator internal fault, sorry. Suggest trying --debug --gdbbt +%Error: Command Failed diff --git a/test_regress/t/t_class_param_noinit_bad.v b/test_regress/t/t_class_param_noinit_bad.v index 52398d589..856842f33 100644 --- a/test_regress/t/t_class_param_noinit_bad.v +++ b/test_regress/t/t_class_param_noinit_bad.v @@ -5,7 +5,7 @@ // SPDX-License-Identifier: CC0-1.0 // No init value is legal with classes, as long as not used without the parameter -class Cls #(int A, int B); +class Cls #(int A, int B, type T); endclass module t(/*AUTOARG*/); diff --git a/test_regress/t/t_lint_iface_array_topmodule_bad.out b/test_regress/t/t_lint_iface_array_topmodule_bad.out index 15778c71b..dda9a0753 100644 --- a/test_regress/t/t_lint_iface_array_topmodule_bad.out +++ b/test_regress/t/t_lint_iface_array_topmodule_bad.out @@ -1,4 +1,4 @@ -%Error: t/t_lint_iface_array_topmodule_bad.v:8:24: Parameter without initial value is never given value (IEEE 1800-2023 6.20.1): 'DW' +%Error: t/t_lint_iface_array_topmodule_bad.v:8:24: Parameter without default value is never given value (IEEE 1800-2023 6.20.1): 'DW' : ... note: In instance 't' 8 | parameter integer DW | ^~ diff --git a/test_regress/t/t_lint_iface_topmodule_bad.out b/test_regress/t/t_lint_iface_topmodule_bad.out index b7a2efc8d..617ac75a9 100644 --- a/test_regress/t/t_lint_iface_topmodule_bad.out +++ b/test_regress/t/t_lint_iface_topmodule_bad.out @@ -1,4 +1,4 @@ -%Error: t/t_lint_iface_topmodule_bad.v:8:23: Parameter without initial value is never given value (IEEE 1800-2023 6.20.1): 'DW' +%Error: t/t_lint_iface_topmodule_bad.v:8:23: Parameter without default value is never given value (IEEE 1800-2023 6.20.1): 'DW' : ... note: In instance 't' 8 | parameter integer DW | ^~ diff --git a/test_regress/t/t_param_default_bad.out b/test_regress/t/t_param_default_bad.out index b08438467..b4a331abb 100644 --- a/test_regress/t/t_param_default_bad.out +++ b/test_regress/t/t_param_default_bad.out @@ -1,4 +1,4 @@ -%Error: t/t_param_default_bad.v:7:26: Parameter without initial value is never given value (IEEE 1800-2023 6.20.1): 'Foo' +%Error: t/t_param_default_bad.v:7:26: Parameter without default value is never given value (IEEE 1800-2023 6.20.1): 'Foo' : ... note: In instance 't.foo' 7 | module m #(parameter int Foo); | ^~~ diff --git a/test_regress/t/t_param_default_presv_bad.out b/test_regress/t/t_param_default_presv_bad.out index 60432957c..6a1db2f52 100644 --- a/test_regress/t/t_param_default_presv_bad.out +++ b/test_regress/t/t_param_default_presv_bad.out @@ -3,7 +3,7 @@ | ^~~ ... For warning description see https://verilator.org/warn/NEWERSTD?v=latest ... Use "/* verilator lint_off NEWERSTD */" and lint_on around source to disable this message. -%Error: t/t_param_default_bad.v:7:26: Parameter without initial value is never given value (IEEE 1800-2023 6.20.1): 'Foo' +%Error: t/t_param_default_bad.v:7:26: Parameter without default value is never given value (IEEE 1800-2023 6.20.1): 'Foo' : ... note: In instance 't.foo' 7 | module m #(parameter int Foo); | ^~~ diff --git a/test_regress/t/t_param_noval_bad.out b/test_regress/t/t_param_noval_bad.out index 432b48da8..14072fd52 100644 --- a/test_regress/t/t_param_noval_bad.out +++ b/test_regress/t/t_param_noval_bad.out @@ -1,7 +1,11 @@ -%Error: t/t_param_noval_bad.v:7:22: Parameter without initial value is never given value (IEEE 1800-2023 6.20.1): 'P' +%Error: t/t_param_noval_bad.v:7:22: Parameter without default value is never given value (IEEE 1800-2023 6.20.1): 'P' : ... note: In instance 't' - 7 | module t #(parameter P); + 7 | module t #(parameter P, parameter type T); | ^ +%Error: t/t_param_noval_bad.v:7:40: Parameter type without default value is never given value (IEEE 1800-2023 6.20.1): 'T' + : ... note: In instance 't' + 7 | module t #(parameter P, parameter type T); + | ^ %Warning-WIDTHTRUNC: t/t_param_noval_bad.v:10:7: Logical operator GENFOR expects 1 bit on the For Test Condition, but For Test Condition's VARREF 'P' generates 32 bits. : ... note: In instance 't' 10 | for (j=0; P; j++) diff --git a/test_regress/t/t_param_noval_bad.v b/test_regress/t/t_param_noval_bad.v index 3dde4948a..61248d8ef 100644 --- a/test_regress/t/t_param_noval_bad.v +++ b/test_regress/t/t_param_noval_bad.v @@ -4,7 +4,7 @@ // any use, without warranty, 2019 by Wilson Snyder. // SPDX-License-Identifier: CC0-1.0 -module t #(parameter P); +module t #(parameter P, parameter type T); generate var j; for (j=0; P; j++)