From 69ac3c14e8e9dde8cae2c7a738bda81161b9e480 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 10 Oct 2024 07:20:44 -0400 Subject: [PATCH] Fix crash with internal assertion on short array initializer (partial #5511) --- src/V3EmitCConstInit.h | 4 +++- test_regress/t/t_unpacked_concat_bad3.out | 4 ++++ test_regress/t/t_unpacked_concat_bad3.py | 17 +++++++++++++++++ test_regress/t/t_unpacked_concat_bad3.v | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test_regress/t/t_unpacked_concat_bad3.out create mode 100755 test_regress/t/t_unpacked_concat_bad3.py create mode 100644 test_regress/t/t_unpacked_concat_bad3.v diff --git a/src/V3EmitCConstInit.h b/src/V3EmitCConstInit.h index 3950efb7a..b91ab9718 100644 --- a/src/V3EmitCConstInit.h +++ b/src/V3EmitCConstInit.h @@ -82,7 +82,9 @@ protected: for (uint64_t n = 0; n < size; ++n) { m_unpackedWord = n; if (n) puts((n % tabMod) ? ", " : ",\n"); - iterateConst(nodep->getIndexDefaultedValuep(n)); + AstNode* const itemp = nodep->getIndexDefaultedValuep(n); + UASSERT_OBJ(itemp, nodep, "Missing array init element"); + iterateConst(itemp); } puts("\n"); puts("}"); diff --git a/test_regress/t/t_unpacked_concat_bad3.out b/test_regress/t/t_unpacked_concat_bad3.out new file mode 100644 index 000000000..4bd30ce0c --- /dev/null +++ b/test_regress/t/t_unpacked_concat_bad3.out @@ -0,0 +1,4 @@ +%Error: Internal Error: t/t_unpacked_concat_bad3.v:9:41: ../V3EmitCConstInit.h:#: Missing array init element + 9 | localparam logic [7:0] TOO_FEW [5] = '{0, 1, 2**8-1}; + | ^~ + ... See the manual at https://verilator.org/verilator_doc.html for more assistance. diff --git a/test_regress/t/t_unpacked_concat_bad3.py b/test_regress/t/t_unpacked_concat_bad3.py new file mode 100755 index 000000000..88e1a07b1 --- /dev/null +++ b/test_regress/t/t_unpacked_concat_bad3.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 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('vlt') + +# Not lint, crashes in V3EmitCConstInit.h +test.compile(fails=True, expect_filename=test.golden_filename) + +test.passes() diff --git a/test_regress/t/t_unpacked_concat_bad3.v b/test_regress/t/t_unpacked_concat_bad3.v new file mode 100644 index 000000000..1efdb08a5 --- /dev/null +++ b/test_regress/t/t_unpacked_concat_bad3.v @@ -0,0 +1,15 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2019 by Driss Hafdi. +// SPDX-License-Identifier: CC0-1.0 + +module t (/*AUTOARG*/); + + localparam logic [7:0] TOO_FEW [5] = '{0, 1, 2**8-1}; // Bad + + initial begin + $display("%p", TOO_FEW); + $stop; + end +endmodule