From 542ffcca608328df308c109f30e7d46b201c2a6a Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 17 Sep 2025 20:42:51 -0400 Subject: [PATCH] Prevent internal error on pattern mismatch --- src/V3Width.cpp | 2 +- test_regress/t/t_array_pattern_scalar_bad.out | 6 ++++++ test_regress/t/t_array_pattern_scalar_bad.py | 16 ++++++++++++++++ test_regress/t/t_array_pattern_scalar_bad.v | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test_regress/t/t_array_pattern_scalar_bad.out create mode 100755 test_regress/t/t_array_pattern_scalar_bad.py create mode 100644 test_regress/t/t_array_pattern_scalar_bad.v diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 8a768e879..35f321208 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -4764,7 +4764,7 @@ class WidthVisitor final : public VNVisitor { E_UNSUPPORTED, "Unsupported: Assignment pattern applies against non struct/union data type: " << dtypep->prettyDTypeNameQ()); - nodep->unlinkFrBack(); + nodep->replaceWith(new AstConst{nodep->fileline(), AstConst::BitFalse{}}); } // Done with the Pattern diff --git a/test_regress/t/t_array_pattern_scalar_bad.out b/test_regress/t/t_array_pattern_scalar_bad.out new file mode 100644 index 000000000..093130bff --- /dev/null +++ b/test_regress/t/t_array_pattern_scalar_bad.out @@ -0,0 +1,6 @@ +%Error-UNSUPPORTED: t/t_array_pattern_scalar_bad.v:9:13: Unsupported: Assignment pattern applies against non struct/union data type: 'bit' + : ... note: In instance 't' + 9 | bit bad = '{1'b1}; + | ^~ + ... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest +%Error: Exiting due to diff --git a/test_regress/t/t_array_pattern_scalar_bad.py b/test_regress/t/t_array_pattern_scalar_bad.py new file mode 100755 index 000000000..55203b6c9 --- /dev/null +++ b/test_regress/t/t_array_pattern_scalar_bad.py @@ -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() diff --git a/test_regress/t/t_array_pattern_scalar_bad.v b/test_regress/t/t_array_pattern_scalar_bad.v new file mode 100644 index 000000000..03415c521 --- /dev/null +++ b/test_regress/t/t_array_pattern_scalar_bad.v @@ -0,0 +1,12 @@ +// 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; + + bit bad = '{1'b1}; // <--- BAD: Can't assign pattern to scalar + + initial $stop; +endmodule