From b64e89f7edb8f10f6f7b9f1646368dfafb7b05b5 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 12 Oct 2021 21:22:59 -0400 Subject: [PATCH] Fix calling new with arguments in same class (#3166). --- Changes | 1 + src/V3Width.cpp | 2 +- test_regress/t/t_class_new.v | 11 +++++++++++ test_regress/t/t_class_new_bad.out | 7 ++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index c098d49bb..e14145ec9 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,7 @@ Verilator 4.213 devel * Fix crash on clang 12/13 (#3148). [Kouping Hsu] * Fix cygwin compile error due to missing -std=gnu++14 (#3149). [Sun Kim] * Fix missing install of vl_file_copy/vl_hier_graph (#3165). [Popolon] +* Fix calling new with arguments in same class (#3166). [Matthew Ballance] Verilator 4.212 2021-09-01 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 4bf588b77..a3b912670 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -3191,7 +3191,7 @@ private: } virtual void visit(AstNew* nodep) override { - if (nodep->didWidthAndSet()) return; + if (nodep->didWidth()) return; AstClassRefDType* refp = m_vup ? VN_CAST(m_vup->dtypeNullSkipRefp(), ClassRefDType) : nullptr; if (!refp) { // e.g. int a = new; diff --git a/test_regress/t/t_class_new.v b/test_regress/t/t_class_new.v index 4e1ff9f48..f15328470 100644 --- a/test_regress/t/t_class_new.v +++ b/test_regress/t/t_class_new.v @@ -33,6 +33,12 @@ class Cls2Arg; imembera = i + 1; imemberb = j + 2; endfunction + + function Cls2Arg clone(); + Cls2Arg ret; + ret = new(imembera, imemberb); + return ret; + endfunction endclass module t (/*AUTOARG*/); @@ -40,6 +46,7 @@ module t (/*AUTOARG*/); ClsNoArg c1; ClsArg c2; Cls2Arg c3; + Cls2Arg c4; c1 = new; if (c1.imembera != 5) $stop; @@ -56,6 +63,10 @@ module t (/*AUTOARG*/); if (c3.imembera != 5) $stop; if (c3.imemberb != 7) $stop; + c4 = c3.clone(); + if (c4.imembera != 6) $stop; + if (c4.imemberb != 9) $stop; + $write("*-* All Finished *-*\n"); $finish; end diff --git a/test_regress/t/t_class_new_bad.out b/test_regress/t/t_class_new_bad.out index ac1b98bf5..d85240aab 100644 --- a/test_regress/t/t_class_new_bad.out +++ b/test_regress/t/t_class_new_bad.out @@ -1,12 +1,13 @@ %Error: t/t_class_new_bad.v:31:16: Too many arguments in function call to FUNC 'new' + : ... In instance t 31 | c1 = new(3); | ^ %Error: t/t_class_new_bad.v:32:16: Too many arguments in function call to FUNC 'new' + : ... In instance t 32 | c2 = new(3); | ^ %Error: t/t_class_new_bad.v:33:12: Missing argument on non-defaulted argument 'i' in function call to FUNC 'new' + : ... In instance t 33 | c3 = new(); | ^~~ -%Error: Internal Error: t/t_class_new_bad.v:33:12: ../V3Broken.cpp:#: Width != WidthMin - 33 | c3 = new(); - | ^~~ +%Error: Exiting due to