From 4b9532fe2420907609756b337ff06f8cbe635154 Mon Sep 17 00:00:00 2001 From: Yutetsu TAKATSUKASA Date: Thu, 22 Feb 2024 17:09:14 +0900 Subject: [PATCH] Improve message for priority case assertion failure (#4905) --- src/V3Assert.cpp | 19 ++++++++++++------- test_regress/t/t_assert_synth_full.out | 2 +- test_regress/t/t_assert_synth_full_vlt.out | 2 +- test_regress/t/t_assert_unique_case.out | 11 +++++++++-- test_regress/t/t_assert_unique_case.pl | 2 +- test_regress/t/t_assert_unique_case_bad.out | 4 ++-- test_regress/t/t_assert_unique_case_bad.v | 21 +++++++++++++++++++++ 7 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index b85a13e6b..a5c584260 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -286,13 +286,19 @@ class AssertVisitor final : public VNVisitor { itemp = VN_AS(itemp->nextp(), CaseItem)) { if (itemp->isDefault()) has_default = true; } + const AstNodeDType* exprDtypep = nodep->exprp()->dtypep()->skipRefp(); + string valFmt; + if (exprDtypep->isIntegralOrPacked()) + valFmt = " for '" + cvtToStr(exprDtypep->widthMin()) + "'h%X'"; if (nodep->fullPragma() || nodep->priorityPragma()) { // Need to add a default if there isn't one already ++m_statAsFull; if (!has_default) { nodep->addItemsp(new AstCaseItem{ nodep->fileline(), nullptr /*DEFAULT*/, - newFireAssert(nodep, "synthesis full_case, but non-match found")}); + newFireAssert( + nodep, nodep->pragmaString() + ", but non-match found" + valFmt, + valFmt.empty() ? nullptr : nodep->exprp()->cloneTreePure(false))}); } } if (nodep->parallelPragma() || nodep->uniquePragma() || nodep->unique0Pragma()) { @@ -344,14 +350,13 @@ class AssertVisitor final : public VNVisitor { new AstLogNot{nodep->fileline(), propp->cloneTreePure(false)}}; AstNodeExpr* const exprp = nodep->exprp(); const string pragmaStr = nodep->pragmaString(); - const string valFmt = "'" + cvtToStr(exprp->dtypep()->widthMin()) + "'h%X'"; if (!allow_none) zeroIfp->addThensp( - newFireAssert(nodep, pragmaStr + ", but none matched for " + valFmt, - exprp->cloneTreePure(false))); - zeroIfp->addElsesp(newFireAssert( - nodep, pragmaStr + ", but multiple matches found for " + valFmt, - exprp->cloneTreePure(false))); + newFireAssert(nodep, pragmaStr + ", but none matched" + valFmt, + valFmt.empty() ? nullptr : exprp->cloneTreePure(false))); + zeroIfp->addElsesp( + newFireAssert(nodep, pragmaStr + ", but multiple matches found" + valFmt, + valFmt.empty() ? nullptr : exprp->cloneTreePure(false))); ohotIfp->addThensp(zeroIfp); ohotIfp->isBoundsCheck(true); // To avoid LATCH warning ohotIfp->branchPred(VBranchPred::BP_UNLIKELY); diff --git a/test_regress/t/t_assert_synth_full.out b/test_regress/t/t_assert_synth_full.out index 2ba86e3b5..2134d5a40 100644 --- a/test_regress/t/t_assert_synth_full.out +++ b/test_regress/t/t_assert_synth_full.out @@ -1,6 +1,6 @@ [0] -Info: t_assert_synth.v:115: top.t.test_info: Start of $info test [0] -Info: t_assert_synth.v:116: top.t.test_info: Middle of $info test [0] -Info: t_assert_synth.v:117: top.t.test_info: End of $info test -[40] %Error: t_assert_synth.v:31: Assertion failed in top.t: synthesis full_case, but non-match found +[40] %Error: t_assert_synth.v:31: Assertion failed in top.t: synthesis full_case, but non-match found for '2'h3' %Error: t/t_assert_synth.v:31: Verilog $stop Aborting... diff --git a/test_regress/t/t_assert_synth_full_vlt.out b/test_regress/t/t_assert_synth_full_vlt.out index a9e2a1ef4..a14c33995 100644 --- a/test_regress/t/t_assert_synth_full_vlt.out +++ b/test_regress/t/t_assert_synth_full_vlt.out @@ -1,6 +1,6 @@ [0] -Info: t_assert_synth.v:115: top.t.test_info: Start of $info test [0] -Info: t_assert_synth.v:116: top.t.test_info: Middle of $info test [0] -Info: t_assert_synth.v:117: top.t.test_info: End of $info test -[40] %Error: t_assert_synth.v:40: Assertion failed in top.t: synthesis full_case, but non-match found +[40] %Error: t_assert_synth.v:40: Assertion failed in top.t: priority case, but non-match found for '2'h3' %Error: t/t_assert_synth.v:40: Verilog $stop Aborting... diff --git a/test_regress/t/t_assert_unique_case.out b/test_regress/t/t_assert_unique_case.out index 46c287188..acf50ebd1 100644 --- a/test_regress/t/t_assert_unique_case.out +++ b/test_regress/t/t_assert_unique_case.out @@ -1,12 +1,19 @@ +[0] %Error: t_assert_unique_case_bad.v:56: Assertion failed in top.t: priority case, but non-match found +match_item0 +[20] %Error: t_assert_unique_case_bad.v:47: Assertion failed in top.t: unique case, but none matched match_item0 match_item0 +[40] %Error: t_assert_unique_case_bad.v:47: Assertion failed in top.t: unique case, but none matched match_item0 match_item0 +[60] %Error: t_assert_unique_case_bad.v:47: Assertion failed in top.t: unique case, but none matched match_item0 match_item0 +[80] %Error: t_assert_unique_case_bad.v:47: Assertion failed in top.t: unique case, but none matched match_item0 +[90] %Error: t_assert_unique_case_bad.v:47: Assertion failed in top.t: unique case, but none matched match_item0 -match_item0 -[90] %Error: t_assert_unique_case_bad.v:36: Assertion failed in top.t: unique case, but multiple matches found for '12'h388' +[90] %Error: t_assert_unique_case_bad.v:38: Assertion failed in top.t: unique case, but multiple matches found for '12'h388' *-* All Finished *-* +[100] %Error: t_assert_unique_case_bad.v:47: Assertion failed in top.t: unique case, but none matched match_item0 diff --git a/test_regress/t/t_assert_unique_case.pl b/test_regress/t/t_assert_unique_case.pl index a9f22933c..74fab282f 100755 --- a/test_regress/t/t_assert_unique_case.pl +++ b/test_regress/t/t_assert_unique_case.pl @@ -12,7 +12,7 @@ scenarios(simulator => 1); top_filename("t/t_assert_unique_case_bad.v"); compile( - verilator_flags2 => ["-x-assign 0 --assert --no-stop-fail"], + verilator_flags2 => ["-x-assign 0 --assert --no-stop-fail +define+NO_STOP_FAIL"], ); execute( diff --git a/test_regress/t/t_assert_unique_case_bad.out b/test_regress/t/t_assert_unique_case_bad.out index 109e2880c..cd97bbb21 100644 --- a/test_regress/t/t_assert_unique_case_bad.out +++ b/test_regress/t/t_assert_unique_case_bad.out @@ -7,6 +7,6 @@ match_item0 match_item0 match_item0 match_item0 -[90] %Error: t_assert_unique_case_bad.v:36: Assertion failed in top.t: unique case, but multiple matches found for '12'h388' -%Error: t/t_assert_unique_case_bad.v:36: Verilog $stop +[90] %Error: t_assert_unique_case_bad.v:38: Assertion failed in top.t: unique case, but multiple matches found for '12'h388' +%Error: t/t_assert_unique_case_bad.v:38: Verilog $stop Aborting... diff --git a/test_regress/t/t_assert_unique_case_bad.v b/test_regress/t/t_assert_unique_case_bad.v index 74f9dc775..c5a3f1dab 100644 --- a/test_regress/t/t_assert_unique_case_bad.v +++ b/test_regress/t/t_assert_unique_case_bad.v @@ -17,6 +17,7 @@ module t (/*AUTOARG*/ logic [31:0] addr; logic [11:0] match_item0, match_item1; int cyc; + string s; initial addr = 32'h380; @@ -25,6 +26,7 @@ module t (/*AUTOARG*/ addr <= 32'h380 + cyc; match_item0 = 12'h 380 + cyc[11:0]; match_item1 = 12'h 390 - cyc[11:0]; + $sformat(s, "%1d", cyc); if (cyc == 9) begin $write("*-* All Finished *-*\n"); $finish; @@ -40,4 +42,23 @@ module t (/*AUTOARG*/ endcase end +`ifdef NO_STOP_FAIL + always_comb begin + unique case (s) + "": ; + "0": ; + "2": ; + "4": ; + "6": ; + endcase + end + always_comb begin + priority case (s) + $sformatf("%1d", cyc - 1): ; + "0": ; + "6": ; + endcase + end +`endif + endmodule