diff --git a/Changes b/Changes index 3d95c097f..a51416c57 100644 --- a/Changes +++ b/Changes @@ -71,6 +71,7 @@ Verilator 5.035 devel * Fix segfault in fork synchronization (#5906). [Krzysztof Bieganski, Antmicro Ltd.] * Fix `new this` (#5909). * Fix LATCH warning for automatic variables (#5918). [Yutetsu TAKATSUKASA] +* Fix %% on elaboration severity tasks (#5922). [Ethan Sifferman] Verilator 5.034 2025-02-24 diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 376894c48..a79c69e42 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -3249,7 +3249,7 @@ class ConstVisitor final : public VNVisitor { } } if (m_doNConst && anyconst) { - // UINFO(9," Display in "<text()<text() << endl); string newFormat; string fmt; bool inPct = false; @@ -3265,9 +3265,9 @@ class ConstVisitor final : public VNVisitor { inPct = false; fmt += ch; switch (std::tolower(ch)) { - case '%': break; // %% - just output a % - case 'm': break; // %m - auto insert "name" - case 'l': break; // %l - auto insert "library" + case '%': break; // %% - still %% + case 'm': break; // %m - still %m - auto insert "name" + case 'l': break; // %l - still %l - auto insert "library" case 't': // FALLTHRU case '^': // %t/%^ - don't know $timeformat so can't constify if (argp) argp = argp->nextp(); diff --git a/src/V3String.cpp b/src/V3String.cpp index 61e180c16..fc8c35e2c 100644 --- a/src/V3String.cpp +++ b/src/V3String.cpp @@ -100,6 +100,20 @@ string VString::quoteAny(const string& str, char tgt, char esc) { return result; } +string VString::dequotePercent(const string& str) { + string result; + char last = '\0'; + for (const char c : str) { + if (last == '%' && c == '%') { + last = '\0'; + } else { + result += c; + last = c; + } + } + return result; +} + string VString::quoteStringLiteralForShell(const string& str) { string result; const char dquote = '"'; diff --git a/src/V3String.h b/src/V3String.h index db21577bd..8e1e97b3e 100644 --- a/src/V3String.h +++ b/src/V3String.h @@ -99,6 +99,8 @@ public: static string quoteBackslash(const string& str) { return quoteAny(str, '\\', '\\'); } // Replace any %'s with %% static string quotePercent(const string& str) { return quoteAny(str, '%', '%'); } + // Replace any %%'s with % + static string dequotePercent(const string& str); // Surround a raw string by double quote and escape if necessary // e.g. input abc's becomes "\"abc\'s\"" static string escapeStringForPath(const string& str); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 8da3687be..3904b975e 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5463,7 +5463,7 @@ class WidthVisitor final : public VNVisitor { userIterateChildren(nodep, WidthVP{SELF, BOTH}.p()); if (!m_paramsOnly) { V3Const::constifyParamsEdit(nodep->fmtp()); // fmtp may change - string text = nodep->fmtp()->text(); + string text = VString::dequotePercent(nodep->fmtp()->text()); if (text.empty()) text = "Elaboration system task message (IEEE 1800-2023 20.11)"; switch (nodep->displayType()) { case VDisplayType::DT_INFO: nodep->v3warn(USERINFO, text); break; diff --git a/test_regress/t/t_assert_comp.out b/test_regress/t/t_assert_comp.out new file mode 100644 index 000000000..5b4075b42 --- /dev/null +++ b/test_regress/t/t_assert_comp.out @@ -0,0 +1,7 @@ +[0] -Info: t_assert_comp.v:23: top.t +[0] -Info: t_assert_comp.v:24: top.t: User run-time info +[0] -Info: t_assert_comp.v:25: top.t: Percent=% PctPct=%% Ten=10 +[0] %Warning: t_assert_comp.v:26: top.t +[0] %Warning: t_assert_comp.v:27: top.t: User run-time warning +[0] %Warning: t_assert_comp.v:28: top.t: 1 +*-* All Finished *-* diff --git a/test_regress/t/t_assert_comp.py b/test_regress/t/t_assert_comp.py index d97aaff01..85bad5b9a 100755 --- a/test_regress/t/t_assert_comp.py +++ b/test_regress/t/t_assert_comp.py @@ -13,6 +13,6 @@ test.scenarios('simulator') test.compile(verilator_flags2=['--assert'], nc_flags2=['+assert']) -test.execute() +test.execute(expect_filename=test.golden_filename) test.passes() diff --git a/test_regress/t/t_assert_comp.v b/test_regress/t/t_assert_comp.v index 50fe0168b..034541c21 100644 --- a/test_regress/t/t_assert_comp.v +++ b/test_regress/t/t_assert_comp.v @@ -6,13 +6,27 @@ module t (/*AUTOARG*/); + localparam TEN = 10; + localparam string PCTPCT = "%%"; + if (0) begin - $info("User compile-time info"); - $warning("User compile-time warning"); - $error("User compile-time error"); + $info; + $info("User elaboration-time info"); + $info("Percent=%% PctPct=%s Ten=%0d", PCTPCT, TEN); + $warning; + $warning("User elaboration-time warning"); + $warning(1); // Check can convert arguments to format + $error("User elaboration-time error"); end initial begin + $info; + $info("User run-time info"); + $info("Percent=%% PctPct=%s Ten=%0d", PCTPCT, TEN); + $warning; + $warning("User run-time warning"); + $warning(1); // Check can convert arguments to format + $write("*-* All Finished *-*\n"); $finish; end diff --git a/test_regress/t/t_assert_comp_bad.out b/test_regress/t/t_assert_comp_bad.out index 7cf00604e..fd91ed9ac 100644 --- a/test_regress/t/t_assert_comp_bad.out +++ b/test_regress/t/t_assert_comp_bad.out @@ -1,43 +1,47 @@ --Info: t/t_assert_comp_bad.v:10:7: Elaboration system task message (IEEE 1800-2023 20.11) +-Info: t/t_assert_comp_bad.v:13:7: Elaboration system task message (IEEE 1800-2023 20.11) : ... note: In instance 't' - 10 | $info; + 13 | $info; | ^~~~~ --Info: t/t_assert_comp_bad.v:11:7: User elaboration-time info +-Info: t/t_assert_comp_bad.v:14:7: User elaboration-time info : ... note: In instance 't' - 11 | $info("User elaboration-time info"); + 14 | $info("User elaboration-time info"); | ^~~~~ -%Warning-USERWARN: t/t_assert_comp_bad.v:12:7: Elaboration system task message (IEEE 1800-2023 20.11) +-Info: t/t_assert_comp_bad.v:15:7: Percent=% PctPct=%% Ten=10 + : ... note: In instance 't' + 15 | $info("Percent=%% PctPct=%s Ten=%0d", PCTPCT, TEN); + | ^~~~~ +%Warning-USERWARN: t/t_assert_comp_bad.v:16:7: Elaboration system task message (IEEE 1800-2023 20.11) : ... note: In instance 't' - 12 | $warning; + 16 | $warning; | ^~~~~~~~ ... For warning description see https://verilator.org/warn/USERWARN?v=latest ... Use "/* verilator lint_off USERWARN */" and lint_on around source to disable this message. -%Warning-USERWARN: t/t_assert_comp_bad.v:13:7: User elaboration-time warning +%Warning-USERWARN: t/t_assert_comp_bad.v:17:7: User elaboration-time warning : ... note: In instance 't' - 13 | $warning("User elaboration-time warning"); + 17 | $warning("User elaboration-time warning"); | ^~~~~~~~ -%Warning-USERWARN: t/t_assert_comp_bad.v:14:7: 1 +%Warning-USERWARN: t/t_assert_comp_bad.v:18:7: 1 : ... note: In instance 't' - 14 | $warning(1); + 18 | $warning(1); | ^~~~~~~~ -%Warning-USERERROR: t/t_assert_comp_bad.v:15:7: Elaboration system task message (IEEE 1800-2023 20.11) +%Warning-USERERROR: t/t_assert_comp_bad.v:19:7: Elaboration system task message (IEEE 1800-2023 20.11) : ... note: In instance 't' - 15 | $error; + 19 | $error; | ^~~~~~ ... For warning description see https://verilator.org/warn/USERERROR?v=latest ... Use "/* verilator lint_off USERERROR */" and lint_on around source to disable this message. -%Warning-USERERROR: t/t_assert_comp_bad.v:16:7: User elaboration-time error +%Warning-USERERROR: t/t_assert_comp_bad.v:20:7: User elaboration-time error : ... note: In instance 't' - 16 | $error("User elaboration-time error"); + 20 | $error("User elaboration-time error"); | ^~~~~~ -%Warning-USERFATAL: t/t_assert_comp_bad.v:17:7: User elaboration-time fatal +%Warning-USERFATAL: t/t_assert_comp_bad.v:21:7: User elaboration-time fatal : ... note: In instance 't' - 17 | $fatal(0, "User elaboration-time fatal"); + 21 | $fatal(0, "User elaboration-time fatal"); | ^~~~~~ ... For warning description see https://verilator.org/warn/USERFATAL?v=latest ... Use "/* verilator lint_off USERFATAL */" and lint_on around source to disable this message. -%Warning-USERFATAL: t/t_assert_comp_bad.v:18:7: Elaboration system task message (IEEE 1800-2023 20.11) +%Warning-USERFATAL: t/t_assert_comp_bad.v:22:7: Elaboration system task message (IEEE 1800-2023 20.11) : ... note: In instance 't' - 18 | $fatal; + 22 | $fatal; | ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_assert_comp_bad.v b/test_regress/t/t_assert_comp_bad.v index 56a32fb8b..d96d99d2e 100644 --- a/test_regress/t/t_assert_comp_bad.v +++ b/test_regress/t/t_assert_comp_bad.v @@ -6,9 +6,13 @@ module t (/*AUTOARG*/); + localparam TEN = 10; + localparam string PCTPCT = "%%"; + if (1) begin $info; $info("User elaboration-time info"); + $info("Percent=%% PctPct=%s Ten=%0d", PCTPCT, TEN); $warning; $warning("User elaboration-time warning"); $warning(1); // Check can convert arguments to format