From 09ca7ea8d1f0f1048eabffe276e8f1b9bf4ae0e3 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 12 Jan 2026 22:56:23 -0500 Subject: [PATCH] Fix emitting unbounded parameters (#6912). Fixes #6912. --- Changes | 1 + src/V3EmitCConstInit.h | 5 +++++ test_regress/t/t_unbounded.v | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Changes b/Changes index 3f93dc295..0b64e4dfb 100644 --- a/Changes +++ b/Changes @@ -389,6 +389,7 @@ Verilator 5.040 2025-08-30 * Fix wide select expansion and substitution (#6341) (#6345). [Geza Lore] * Fix upcasting class type parameters (#6344). [Krzysztof Bieganski, Antmicro Ltd.] * Fix undefined weak link for Apple GCC etc (#6348). [Congcong Cai] +* Fix emitting unbounded parameters (#6912). * Fix syntax error on unsupported defparam array (#6915). diff --git a/src/V3EmitCConstInit.h b/src/V3EmitCConstInit.h index ab88a5332..59427cfb5 100644 --- a/src/V3EmitCConstInit.h +++ b/src/V3EmitCConstInit.h @@ -99,6 +99,11 @@ protected: UASSERT_OBJ(!num.isFourState(), nodep, "4-state value in constant pool"); putns(nodep, num.emitC()); } + void visit(AstUnbounded* nodep) override { + // e.g. when emitting a public parameter's "$" value + // But Unbounded is only special during elaboration, so just use zero + putns(nodep, "0"); + } // Default void visit(AstNode* nodep) override { // LCOV_EXCL_START diff --git a/test_regress/t/t_unbounded.v b/test_regress/t/t_unbounded.v index a8b6d3bba..4d61f8872 100644 --- a/test_regress/t/t_unbounded.v +++ b/test_regress/t/t_unbounded.v @@ -4,20 +4,20 @@ // any use, without warranty, 2014 by Wilson Snyder. // SPDX-License-Identifier: CC0-1.0 -module t(); +module t; - localparam UNB = $; - localparam int UNB2 = $; - localparam SIX = 6; + parameter int UNB /*verilator public*/ = $; + localparam int UNB2 = $; + localparam SIX = 6; - initial begin - if ($bits($isunbounded(0)) !== 1) $stop; - if ($isunbounded(0) !== 1'b0) $stop; - if ($isunbounded(SIX) !== 0) $stop; - if ($isunbounded($) !== 1) $stop; - if ($isunbounded(UNB) !== 1) $stop; - if ($isunbounded(UNB2) !== 1) $stop; - $write("*-* All Finished *-*\n"); - $finish; - end + initial begin + if ($bits($isunbounded(0)) !== 1) $stop; + if ($isunbounded(0) !== 1'b0) $stop; + if ($isunbounded(SIX) !== 0) $stop; + if ($isunbounded($) !== 1) $stop; + if ($isunbounded(UNB) !== 1) $stop; + if ($isunbounded(UNB2) !== 1) $stop; + $write("*-* All Finished *-*\n"); + $finish; + end endmodule