Fix hang on bad pattern keys, bug1364.

This commit is contained in:
Wilson Snyder 2018-11-01 19:03:52 -04:00
parent ad2929dff0
commit 45c9939a5e
4 changed files with 80 additions and 26 deletions

View File

@ -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

View File

@ -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 '"<<textp->text()<<"' not found as member");
continue;
}
} else {
patp->keyp()->v3error("Assignment pattern key not"
" supported/understood: "<<patp->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<PatMap::iterator, bool> 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 '"
<<textp->text()<<"' not found as member");
break;
}
} else {
patp->keyp()->v3error(
"Assignment pattern key not supported/understood: "
<<patp->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<PatMap::iterator, bool> 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);

View File

@ -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;

View File

@ -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