From d2a8fa74409d5fc35db36b67fd15aa0dbccbf0f4 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 17 Nov 2021 17:46:08 -0500 Subject: [PATCH] Fix display of empty string constant (#3207). --- Changes | 1 + src/V3Number.h | 1 + src/verilog.y | 10 +++++++++- test_regress/t/t_display.out | 1 + test_regress/t/t_display.v | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 8b62759f9..8c089b387 100644 --- a/Changes +++ b/Changes @@ -22,6 +22,7 @@ Verilator 4.215 devel * Fix array method names with parenthesis (#3181) (#3183). [Teng Huang] * Fix split_var assign merging (#3177) (#3179). [Yutetsu TAKATSUKASA] * Fix nested generate if genblk naming (#3189). [yanx21] +* Fix display of empty string constant (#3207). [Julie Schwartz] Verilator 4.214 2021-10-17 diff --git a/src/V3Number.h b/src/V3Number.h index f43fd6619..e62ad8562 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -233,6 +233,7 @@ public: V3Number(String, AstNode* nodep, const string& value) { init(nodep, 0); setString(value); + m_fromString = true; } class Null {}; V3Number(Null, AstNode* nodep) { diff --git a/src/verilog.y b/src/verilog.y index 7d6e44d16..18779d05e 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -5006,7 +5006,15 @@ str: // yaSTRING but with \{escapes} need decoded strAsInt: yaSTRING - { $$ = new AstConst{$1, AstConst::VerilogStringLiteral(), GRAMMARP->deQuote($1, *$1)}; } + { if ($1->empty()) { + // else "" is not representable as number as is width 0 + // TODO all strings should be represented this way + // until V3Width converts as/if needed to a numerical constant + $$ = new AstConst{$1, AstConst::String{}, GRAMMARP->deQuote($1, *$1)}; + } else { + $$ = new AstConst{$1, AstConst::VerilogStringLiteral(), GRAMMARP->deQuote($1, *$1)}; + } + } ; strAsIntIgnore: // strAsInt, but never matches for when expr shouldn't parse strings diff --git a/test_regress/t/t_display.out b/test_regress/t/t_display.out index 0475a1952..5b3ba2aa9 100644 --- a/test_regress/t/t_display.out +++ b/test_regress/t/t_display.out @@ -56,6 +56,7 @@ hello, from a concatenated string. hello, from a concatenated format string [0]. extra argument: 0 0 : pre argument after +empty: >< [0] Embedded tab ' ' and <#013> return [0] Embedded multiline diff --git a/test_regress/t/t_display.v b/test_regress/t/t_display.v index 3f191f9b1..fa280f616 100644 --- a/test_regress/t/t_display.v +++ b/test_regress/t/t_display.v @@ -149,6 +149,7 @@ module t; $write("hel", "lo, fr", "om a concatenated format string [%0t].\n", $time); $display("extra argument: ", $time); $display($time,, ": pre argument",, "after"); + $display("empty: >%s<", ""); $write("[%0t] Embedded tab '\t' and \r return\n", $time); $display("[%0t] Embedded\ multiline", $time);