From d56b923eaabc2397731041fcd9998f30ef3552d9 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 26 Nov 2020 11:50:50 -0500 Subject: [PATCH] Fix 'randomize() with {}' crash --- src/V3LinkDot.cpp | 12 +++++++----- test_regress/t/t_with.v | 6 ++++++ test_regress/t/t_with_bbox.pl | 21 --------------------- 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100755 test_regress/t/t_with_bbox.pl diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 1c05ae13c..c2058735f 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1290,11 +1290,13 @@ class LinkDotFindVisitor final : public AstNVisitor { VL_DO_DANGLING(argp->unlinkFrBackWithNext()->deleteTree(), argp); } // Type depends on the method used, let V3Width figure it out later - auto* indexArgRefp = new AstLambdaArgRef(argFl, name + "__DOT__index", true); - auto* valueArgRefp = new AstLambdaArgRef(argFl, name, false); - auto* newp = new AstWith(nodep->fileline(), indexArgRefp, valueArgRefp, - nodep->exprp()->unlinkFrBackWithNext()); - funcrefp->addPinsp(newp); + const auto indexArgRefp = new AstLambdaArgRef(argFl, name + "__DOT__index", true); + const auto valueArgRefp = new AstLambdaArgRef(argFl, name, false); + if (nodep->exprp()) { // Else empty expression and pretend no "with" + const auto newp = new AstWith(nodep->fileline(), indexArgRefp, valueArgRefp, + nodep->exprp()->unlinkFrBackWithNext()); + funcrefp->addPinsp(newp); + } nodep->replaceWith(funcrefp->unlinkFrBack()); VL_DO_DANGLING(nodep->deleteTree(), nodep); } diff --git a/test_regress/t/t_with.v b/test_regress/t/t_with.v index 015cdc295..3a3da8ff2 100644 --- a/test_regress/t/t_with.v +++ b/test_regress/t/t_with.v @@ -26,6 +26,12 @@ module t (/*AUTOARG*/); found = aliases.find with (item == i); aliases.find with (item == i); +`ifdef VERILATOR + // No expression (e.g. x.randomize() with {}) + // Hack until randomize() supported + found = aliases.sort() with {}; +`endif + // Unique (array method) id = 4; found = aliases.find with (id); diff --git a/test_regress/t/t_with_bbox.pl b/test_regress/t/t_with_bbox.pl deleted file mode 100755 index cc3646920..000000000 --- a/test_regress/t/t_with_bbox.pl +++ /dev/null @@ -1,21 +0,0 @@ -#!/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(vlt => 1); - -top_filename("t/t_with_unsup.v"); - -lint( - verilator_flags => ["--bbox-unsup"], - fails => 1, - ); - -ok(1); -1;