Add error on too many pattern members for structure

This commit is contained in:
Wilson Snyder 2025-08-03 17:26:51 -04:00
parent f106c1eaec
commit 52ac3b3a0d
4 changed files with 49 additions and 9 deletions

View File

@ -4680,17 +4680,17 @@ class WidthVisitor final : public VNVisitor {
"Assignment pattern key not supported/understood: "
<< patp->keyp()->prettyTypeName());
}
} else {
} else if (memp) {
// constant expr
if (memp) {
const std::pair<PatMap::iterator, bool> ret
= patmap.emplace(memp, patp);
if (!ret.second) {
patp->v3error("Assignment pattern contains duplicate entry: "
<< VN_AS(patp->keyp(), Text)->text());
}
memp = VN_AS(memp->nextp(), MemberDType);
const std::pair<PatMap::iterator, bool> ret = patmap.emplace(memp, patp);
if (!ret.second) {
patp->v3error("Assignment pattern contains duplicate entry: "
<< VN_AS(patp->keyp(), Text)->text());
}
memp = VN_AS(memp->nextp(), MemberDType);
} else {
patp->v3error(
"Assignment pattern contains more entries than structure members");
}
} while (false);

View File

@ -0,0 +1,6 @@
%Error: t/t_struct_pat_toomany_bad.v:12:18: Assignment pattern contains more entries than structure members
: ... note: In instance 't'
12 | } sp = '{1, 2, 3};
| ^
... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance.
%Error: Exiting due to

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 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
import vltest_bootstrap
test.scenarios('linter')
test.lint(fails=True, expect_filename=test.golden_filename)
test.passes()

View File

@ -0,0 +1,18 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t;
struct packed {
int m_i;
byte m_b;
} sp = '{1, 2, 3}; // BAD, too many elements
initial begin
$display("FAILED");
end
endmodule