diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 24e3ced87..af3f4e00d 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -110,6 +110,7 @@ Ilya Barkov Iru Cai Ivan Vnučec Iztok Jeras +Jaeuk Lee (이재욱) Jake Merdich Jakub Michalski Jakub Wasilewski diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 802fe155d..9817e4f57 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1002,6 +1002,14 @@ class WidthVisitor final : public VNVisitor { } } if (m_vup->final()) { + const AstNode* backp = nodep->backp(); + if (VN_IS(backp, SFormatArg)) backp = backp->backp(); + if (VN_IS(backp, SFormatF)) { + nodep->v3error( + "Streaming concatenation cannot be used in an implicitly cast context " + "(IEEE 1800-2023 11.4.17)\n" + << nodep->warnMore() << "... Suggest use a cast"); + } if (!nodep->dtypep()->widthSized()) { // See also error in V3Number nodeForUnsizedWarning(nodep)->v3warn( diff --git a/test_regress/t/t_display_stream_bad.out b/test_regress/t/t_display_stream_bad.out new file mode 100644 index 000000000..0eb1912e5 --- /dev/null +++ b/test_regress/t/t_display_stream_bad.out @@ -0,0 +1,17 @@ +%Error: t/t_display_stream_bad.v:11:15: Streaming concatenation cannot be used in an implicitly cast context (IEEE 1800-2023 11.4.17) + : ... note: In instance 't' + : ... Suggest use a cast + 11 | $display({<<{value}}); + | ^~ + ... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance. +%Error: t/t_display_stream_bad.v:12:22: Streaming concatenation cannot be used in an implicitly cast context (IEEE 1800-2023 11.4.17) + : ... note: In instance 't' + : ... Suggest use a cast + 12 | $display("%0d", {<<{value}}); + | ^~ +%Error: t/t_display_stream_bad.v:13:29: Streaming concatenation cannot be used in an implicitly cast context (IEEE 1800-2023 11.4.17) + : ... note: In instance 't' + : ... Suggest use a cast + 13 | void'($sformatf("%0d", {<<{value}})); + | ^~ +%Error: Exiting due to diff --git a/test_regress/t/t_display_stream_bad.py b/test_regress/t/t_display_stream_bad.py new file mode 100755 index 000000000..38cf36b43 --- /dev/null +++ b/test_regress/t/t_display_stream_bad.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# 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-FileCopyrightText: 2026 Wilson Snyder +# 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_display_stream_bad.v b/test_regress/t/t_display_stream_bad.v new file mode 100644 index 000000000..3ff9e0472 --- /dev/null +++ b/test_regress/t/t_display_stream_bad.v @@ -0,0 +1,15 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain. +// SPDX-FileCopyrightText: 2026 Wilson Snyder +// SPDX-License-Identifier: CC0-1.0 + +module t; + int value = 1; + + initial begin + $display({<<{value}}); + $display("%0d", {<<{value}}); + void'($sformatf("%0d", {<<{value}})); + end +endmodule