From db60b92613d6b87397e3828929a4286a39c3ed02 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 27 Mar 2024 08:41:58 -0400 Subject: [PATCH] Fix internal error on missing pattern key (#5023) --- Changes | 1 + src/V3Width.cpp | 17 +++++++++++------ test_regress/t/t_assoc_nokey_bad.out | 9 +++++++++ test_regress/t/t_assoc_nokey_bad.pl | 19 +++++++++++++++++++ test_regress/t/t_assoc_nokey_bad.v | 20 ++++++++++++++++++++ 5 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 test_regress/t/t_assoc_nokey_bad.out create mode 100755 test_regress/t/t_assoc_nokey_bad.pl create mode 100644 test_regress/t/t_assoc_nokey_bad.v diff --git a/Changes b/Changes index 9dfb5a866..e644a6031 100644 --- a/Changes +++ b/Changes @@ -48,6 +48,7 @@ Verilator 5.023 devel * Fix inout ports of unpacked struct type (#5000). [Ryszard Rozak, Antmicro Ltd.] * Fix `unique {}` constraints missing semicolon (#5001) * Fix preprocessor to respect strings in joins (#5007) +* Fix internal error on missing pattern key (#5023) Verilator 5.022 2024-02-24 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 44a2dea22..bb36b0063 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -4284,9 +4284,14 @@ class WidthVisitor final : public VNVisitor { patp = VN_AS(patp->nextp(), PatMember)) { patp->dtypep(arrayDtp->subDTypep()); AstNodeExpr* const valuep = patternMemberValueIterate(patp); - AstNode* const keyp = patp->keyp(); - auto* const newap - = new AstSetAssoc{nodep->fileline(), newp, keyp->unlinkFrBack(), valuep}; + AstNode* keyp = patp->keyp(); + if (!keyp) { + patp->v3error("Missing pattern key (need an expression then a ':')"); + keyp = new AstConst{nodep->fileline(), AstConst::Signed32{}, 0}; + } else { + keyp->unlinkFrBack(); + } + AstSetAssoc* const newap = new AstSetAssoc{nodep->fileline(), newp, keyp, valuep}; newap->dtypeFrom(arrayDtp); newp = newap; } @@ -4305,7 +4310,7 @@ class WidthVisitor final : public VNVisitor { patp->dtypep(arrayDtp->subDTypep()); AstNodeExpr* const valuep = patternMemberValueIterate(patp); AstNode* const keyp = patp->keyp(); - auto* const newap + AstSetWildcard* const newap = new AstSetWildcard{nodep->fileline(), newp, keyp->unlinkFrBack(), valuep}; newap->dtypeFrom(arrayDtp); newp = newap; @@ -4321,7 +4326,7 @@ class WidthVisitor final : public VNVisitor { patp = VN_AS(patp->nextp(), PatMember)) { patp->dtypep(arrayp->subDTypep()); AstNodeExpr* const valuep = patternMemberValueIterate(patp); - auto* const newap = new AstConsDynArray{nodep->fileline(), valuep, newp}; + AstConsDynArray* const newap = new AstConsDynArray{nodep->fileline(), valuep, newp}; newap->dtypeFrom(arrayp); newp = newap; } @@ -4336,7 +4341,7 @@ class WidthVisitor final : public VNVisitor { patp = VN_AS(patp->nextp(), PatMember)) { patp->dtypep(arrayp->subDTypep()); AstNodeExpr* const valuep = patternMemberValueIterate(patp); - auto* const newap = new AstConsQueue{nodep->fileline(), valuep, newp}; + AstConsQueue* const newap = new AstConsQueue{nodep->fileline(), valuep, newp}; newap->dtypeFrom(arrayp); newp = newap; } diff --git a/test_regress/t/t_assoc_nokey_bad.out b/test_regress/t/t_assoc_nokey_bad.out new file mode 100644 index 000000000..4e172e2f5 --- /dev/null +++ b/test_regress/t/t_assoc_nokey_bad.out @@ -0,0 +1,9 @@ +%Error: t/t_assoc_nokey_bad.v:12:28: Missing pattern key (need an expression then a ':') + : ... note: In instance 't' + 12 | int dict[string] = '{1, 2}; + | ^ +%Error: t/t_assoc_nokey_bad.v:12:31: Missing pattern key (need an expression then a ':') + : ... note: In instance 't' + 12 | int dict[string] = '{1, 2}; + | ^ +%Error: Exiting due to diff --git a/test_regress/t/t_assoc_nokey_bad.pl b/test_regress/t/t_assoc_nokey_bad.pl new file mode 100755 index 000000000..c42f6c90d --- /dev/null +++ b/test_regress/t/t_assoc_nokey_bad.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(linter => 1); + +lint( + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_assoc_nokey_bad.v b/test_regress/t/t_assoc_nokey_bad.v new file mode 100644 index 000000000..6125f52dc --- /dev/null +++ b/test_regress/t/t_assoc_nokey_bad.v @@ -0,0 +1,20 @@ +// DESCRIPTION: Verilator: Verilog Test module for SystemVerilog 'alias' +// +// Simple bi-directional alias test. +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2024 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +module t (/*AUTOARG*/); + + initial begin + int dict[string] = '{1, 2}; + int dict2[string] = '{3: 4}; // Legal due to value-to-string conversion + $display("dict=%p", dict); + $display("dict2=%p", dict2); + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule