From 13ddd0bc1cb598746dbfb24d5eb21973e1f3e0fa Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 13 Jun 2021 12:38:31 -0400 Subject: [PATCH] Fix error on unsupported recursive functions (#2957). --- Changes | 2 +- src/V3LinkDot.cpp | 16 +++++++++++----- test_regress/t/t_func_bad3.out | 5 +++++ test_regress/t/t_func_bad3.pl | 19 +++++++++++++++++++ test_regress/t/t_func_bad3.v | 15 +++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 test_regress/t/t_func_bad3.out create mode 100755 test_regress/t/t_func_bad3.pl create mode 100644 test_regress/t/t_func_bad3.v diff --git a/Changes b/Changes index d1b63d9dc..70f794f7e 100644 --- a/Changes +++ b/Changes @@ -19,7 +19,7 @@ Verilator 4.205 devel **Minor:** * Merge const static data globally into a new constant pool (#3013). [Geza Lore] - +* Fix error on unsupported recursive functions (#2957). [Trefor Southwell] Verilator 4.204 2021-06-12 diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 102e92034..05469e928 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2666,11 +2666,17 @@ private: UINFO(7, " ErrFtask curSymp=se" << cvtToHex(m_curSymp) << " dotSymp=se" << cvtToHex(dotSymp) << endl); if (foundp) { - nodep->v3error("Found definition of '" - << m_ds.m_dotText << (m_ds.m_dotText == "" ? "" : ".") - << nodep->prettyName() << "'" - << " as a " << foundp->nodep()->typeName() - << " but expected a task/function"); + if (VN_IS(foundp->nodep(), Var) && m_ds.m_dotText == "" && m_ftaskp + && m_ftaskp->name() == foundp->nodep()->name()) { + nodep->v3warn(E_UNSUPPORTED, "Unsupported: Recursive function call " + << nodep->prettyNameQ()); + } else { + nodep->v3error("Found definition of '" + << m_ds.m_dotText << (m_ds.m_dotText == "" ? "" : ".") + << nodep->prettyName() << "'" + << " as a " << foundp->nodep()->typeName() + << " but expected a task/function"); + } } else if (VN_IS(nodep, New) && m_statep->forPrearray()) { // Resolved in V3Width } else if (nodep->dotted() == "") { diff --git a/test_regress/t/t_func_bad3.out b/test_regress/t/t_func_bad3.out new file mode 100644 index 000000000..628c1a173 --- /dev/null +++ b/test_regress/t/t_func_bad3.out @@ -0,0 +1,5 @@ +%Error-UNSUPPORTED: t/t_func_bad3.v:12:27: Unsupported: Recursive function call 'recurse_self' + 12 | else recurse_self = recurse_self(i - 1) + 1; + | ^~~~~~~~~~~~ + ... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest +%Error: Exiting due to diff --git a/test_regress/t/t_func_bad3.pl b/test_regress/t/t_func_bad3.pl new file mode 100755 index 000000000..877e6133a --- /dev/null +++ b/test_regress/t/t_func_bad3.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 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 + +scenarios(simulator => 1); + +compile( + fails => $Self->{vlt_all}, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_func_bad3.v b/test_regress/t/t_func_bad3.v new file mode 100644 index 000000000..9b8d672f0 --- /dev/null +++ b/test_regress/t/t_func_bad3.v @@ -0,0 +1,15 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2003 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +module t; + + function recurse_self; + input i; + if (i == 0) recurse_self = 0; + else recurse_self = recurse_self(i - 1) + 1; + endfunction + +endmodule