From c2e44dbd994e2f3e3cd6deae0cde189b9d8b888b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 8 Aug 2024 03:32:07 -0400 Subject: [PATCH] Fix $sformat with array arguments (#5330). --- Changes | 1 + src/V3Width.cpp | 7 ++++++- test_regress/t/t_sys_sformat.v | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 8c071d092..ca051a6ee 100644 --- a/Changes +++ b/Changes @@ -57,6 +57,7 @@ Verilator 5.027 devel * Fix Python3 path discovery in make flows to avoid mixing system and user python interpreters (#5307) [Markus Krause] * Fix make flows to pass PYTHON3 (like PERL) (#5307) (#5308). [Markus Krause] * Fix stringify in nested preprocessor macros (#5323). [Krzysztof Bieganski, Antmicro Ltd.] +* Fix $sformat with array arguments (#5330). [Abe Jordan] * Fix ==? and !=? with X values. * Fix CPU time being zero. * Fix inline function ref port persistence. diff --git a/src/V3Width.cpp b/src/V3Width.cpp index fd0a85b09..a6d7c5d5f 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1203,7 +1203,7 @@ class WidthVisitor final : public VNVisitor { userIterateAndNext(nodep->attrp(), WidthVP{SELF, BOTH}.p()); AstNode* const selp = V3Width::widthSelNoIterEdit(nodep); if (selp != nodep) { - nodep = nullptr; + VL_DANGLING(nodep); userIterate(selp, m_vup); return; } @@ -5051,6 +5051,11 @@ class WidthVisitor final : public VNVisitor { } } + void visit(AstSFormat* nodep) override { + assertAtStatement(nodep); + userIterateAndNext(nodep->fmtp(), WidthVP{SELF, BOTH}.p()); + userIterateAndNext(nodep->lhsp(), WidthVP{SELF, BOTH}.p()); + } void visit(AstSFormatF* nodep) override { // Excludes NodeDisplay, see below if (m_vup && !m_vup->prelim()) return; // Can be called as statement or function diff --git a/test_regress/t/t_sys_sformat.v b/test_regress/t/t_sys_sformat.v index c794e6ff6..ae1af86aa 100644 --- a/test_regress/t/t_sys_sformat.v +++ b/test_regress/t/t_sys_sformat.v @@ -17,6 +17,7 @@ module t; reg [48*8:1] str2; string str3; + reg [39:0] instruction_str [1:0]; real r; @@ -87,6 +88,11 @@ module t; `ifdef TEST_VERBOSE $display("str3=%0s", str3); `endif if (str3 != "foo") $stop; + $sformat(instruction_str[0], "%s", "Hello"); + $sformat(instruction_str[1], "%s", "World"); + if (instruction_str[0] != "Hello") $stop; + if (instruction_str[1] != "World") $stop; + $write("*-* All Finished *-*\n"); $finish; end