From 8b647f09775b3a1e2153f9ab956ffaf5fa4ad9be Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 2 Jun 2020 08:00:37 -0400 Subject: [PATCH] Fix error on UNPACKED in parser. (#1541) --- bin/verilator | 5 ++++- src/verilog.y | 2 +- test_regress/t/t_struct_unpacked2.out | 8 ++++++++ test_regress/t/t_struct_unpacked2.pl | 19 +++++++++++++++++++ test_regress/t/t_struct_unpacked2.v | 21 +++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test_regress/t/t_struct_unpacked2.out create mode 100755 test_regress/t/t_struct_unpacked2.pl create mode 100644 test_regress/t/t_struct_unpacked2.v diff --git a/bin/verilator b/bin/verilator index cd0f84583..b8d345107 100755 --- a/bin/verilator +++ b/bin/verilator @@ -4816,7 +4816,10 @@ correctly. Warns that unpacked structs and unions are not supported. Ignoring this warning will make Verilator treat the structure as packed, -which may make Verilator simulations differ from other simulators. +which may make Verilator simulations differ from other simulators. This +downgrading may also result what would normally be a legal unpacked +struct/array inside an unpacked struct/array becomming an illegal unpacked +struct/array inside a packed struct/array. =item UNSIGNED diff --git a/src/verilog.y b/src/verilog.y index 2d3bf6475..5a778c838 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1667,7 +1667,7 @@ list_of_member_decl_assignments: // Derived from IEEE: list_of_variable_d member_decl_assignment: // Derived from IEEE: variable_decl_assignment // // At present we allow only packed structures/unions. So this is different from variable_decl_assignment id variable_dimensionListE - { if ($2) $2->v3error("Unsupported: Unpacked array in packed struct/union"); + { if ($2) $2->v3warn(UNPACKED, "Unsupported: Unpacked array in packed struct/union (struct/union converted to unpacked)"); $$ = new AstMemberDType($1, *$1, VFlagChildDType(), AstNodeDType::cloneTreeNull(GRAMMARP->m_memDTypep, true)); PARSEP->tagNodep($$); diff --git a/test_regress/t/t_struct_unpacked2.out b/test_regress/t/t_struct_unpacked2.out new file mode 100644 index 000000000..3d938df82 --- /dev/null +++ b/test_regress/t/t_struct_unpacked2.out @@ -0,0 +1,8 @@ +%Warning-UNPACKED: t/t_struct_unpacked2.v:10:13: Unsupported: Unpacked array in packed struct/union (struct/union converted to unpacked) + 10 | int b [2]; + | ^ + ... Use "/* verilator lint_off UNPACKED */" and lint_on around source to disable this message. +%Warning-UNPACKED: t/t_struct_unpacked2.v:9:12: Unsupported: Unpacked struct/union + 9 | typedef struct { + | ^~~~~~ +%Error: Exiting due to diff --git a/test_regress/t/t_struct_unpacked2.pl b/test_regress/t/t_struct_unpacked2.pl new file mode 100755 index 000000000..59ba0d6c6 --- /dev/null +++ b/test_regress/t/t_struct_unpacked2.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 => $Self->{vlt_all}, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_struct_unpacked2.v b/test_regress/t/t_struct_unpacked2.v new file mode 100644 index 000000000..e7c6ff9ff --- /dev/null +++ b/test_regress/t/t_struct_unpacked2.v @@ -0,0 +1,21 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2009 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +module x; + + typedef struct { + int b [2]; + } notpacked_t; + + notpacked_t n; + + initial begin + n.b[0] = 1; + if (n.b[0] != 1) $stop; + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule