diff --git a/Changes b/Changes index 42ff6354a..418257f73 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix --trace-lxt2 compile error on MinGW, msg2711. [HyungKi Jeong] +**** Fix hang on bad pattern keys, bug1364. [Matt Myers] + * Verilator 4.006 2018-10-27 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 219fa8b2b..0aff35210 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1756,32 +1756,39 @@ private: AstMemberDType* memp = classp->membersp(); AstPatMember* patp = VN_CAST(nodep->itemsp(), PatMember); for (; memp || patp; ) { - if (patp) { - if (patp->keyp()) { - if (AstText* textp = VN_CAST(patp->keyp(), Text)) { - memp = classp->findMember(textp->text()); - if (!memp) { - patp->keyp()->v3error("Assignment pattern key '"<text()<<"' not found as member"); - continue; - } - } else { - patp->keyp()->v3error("Assignment pattern key not" - " supported/understood: "<keyp()->prettyTypeName()); - } - } - } - if (memp && !patp) { - // Missing init elements, warn below - memp=NULL; patp=NULL; break; - } else if (!memp && patp) { patp->v3error("Assignment pattern contains too many elements"); - memp=NULL; patp=NULL; break; - } else { - std::pair ret = patmap.insert(make_pair(memp, patp)); - if (!ret.second) { - patp->v3error("Assignment pattern contains duplicate entry: " - << VN_CAST(patp->keyp(), Text)->text()); - } - } + do { + if (patp) { + if (patp->keyp()) { + if (AstText* textp = VN_CAST(patp->keyp(), Text)) { + memp = classp->findMember(textp->text()); + if (!memp) { + patp->keyp()->v3error( + "Assignment pattern key '" + <text()<<"' not found as member"); + break; + } + } else { + patp->keyp()->v3error( + "Assignment pattern key not supported/understood: " + <keyp()->prettyTypeName()); + } + } + } + if (memp && !patp) { + // Missing init elements, warn below + memp=NULL; patp=NULL; break; + } else if (!memp && patp) { + patp->v3error("Assignment pattern contains too many elements"); + memp=NULL; patp=NULL; break; + } else { + std::pair ret + = patmap.insert(make_pair(memp, patp)); + if (!ret.second) { + patp->v3error("Assignment pattern contains duplicate entry: " + << VN_CAST(patp->keyp(), Text)->text()); + } + } + } while(0); // Next if (memp) memp = VN_CAST(memp->nextp(), MemberDType); if (patp) patp = VN_CAST(patp->nextp(), PatMember); diff --git a/test_regress/t/t_array_pattern_bad.pl b/test_regress/t/t_array_pattern_bad.pl new file mode 100755 index 000000000..9bcc2f2a9 --- /dev/null +++ b/test_regress/t/t_array_pattern_bad.pl @@ -0,0 +1,20 @@ +#!/usr/bin/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. + +scenarios(simulator => 1); + +compile( + fails => 1, + expect => +q{%Error: t/t_array_pattern_bad.v:23: Assignment pattern key 'valids' not found as member +.*%Error: Exiting due to.*}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_array_pattern_bad.v b/test_regress/t/t_array_pattern_bad.v new file mode 100644 index 000000000..563de8ccd --- /dev/null +++ b/test_regress/t/t_array_pattern_bad.v @@ -0,0 +1,25 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2018 by Wilson Snyder. + +// bug1364 + +module t (/*AUTOARG*/ + // Inputs + clk, res + ); + input clk; + input res; + + typedef struct packed { + logic [3:0] port_num; + } info_t; + + info_t myinfo; + + always_comb + myinfo = '{default: '0, + valids: '1}; + +endmodule