diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index fc29de08c..4540e5575 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -439,7 +439,9 @@ class AssertVisitor final : public VNVisitor { } else { ++m_statAsNotImm; } - if (!passsp && !failsp) failsp = newFireAssertUnchecked(nodep, "'assert' failed."); + if (!passsp && !failsp) + failsp = newFireAssertUnchecked( + nodep, VN_IS(nodep, AssertIntrinsic) ? "'$cast' failed." : "'assert' failed."); } else { nodep->v3fatalSrc("Unknown node type"); } diff --git a/test_regress/t/t_castdyn.v b/test_regress/t/t_castdyn.v index d1b960150..c167c0927 100644 --- a/test_regress/t/t_castdyn.v +++ b/test_regress/t/t_castdyn.v @@ -9,76 +9,76 @@ endclass class BasedA extends Base; endclass class BasedB extends Base; - static function BasedB getBasedB(bit getNull); - BasedB b = new; - return getNull ? null : b; - endfunction + static function BasedB getBasedB(bit getNull); + BasedB b = new; + return getNull ? null : b; + endfunction endclass module t; - int i; - int a; - int ao; + int i; + int a; + int ao; - Base b; - Base bo; - BasedA ba; - BasedA bao; - BasedB bb; - BasedB bbo; + Base b; + Base bo; + BasedA ba; + BasedA bao; + BasedB bb; + BasedB bbo; - // verilator lint_off CASTCONST + // verilator lint_off CASTCONST - initial begin - a = 1234; - i = $cast(ao, a); - if (i != 1) $stop; - if (ao != 1234) $stop; + initial begin + a = 1234; + i = $cast(ao, a); + if (i != 1) $stop; + if (ao != 1234) $stop; - a = 12345; - $cast(ao, a); - if (ao != 12345) $stop; + a = 12345; + $cast(ao, a); + if (ao != 12345) $stop; - i = $cast(ao, 2.1 * 3.7); - if (i != 1) $stop; - if (ao != 8) $stop; + i = $cast(ao, 2.1 * 3.7); + if (i != 1) $stop; + if (ao != 8) $stop; - i = $cast(bo, null); - if (i != 1) $stop; - if (bo != null) $stop; + i = $cast(bo, null); + if (i != 1) $stop; + if (bo != null) $stop; - ba = new; - b = ba; - i = $cast(bao, b); - if (i != 1) $stop; - if (b != ba) $stop; + ba = new; + b = ba; + i = $cast(bao, b); + if (i != 1) $stop; + if (b != ba) $stop; - bb = new; - b = bb; - i = $cast(bbo, b); - if (i != 1) $stop; - if (b != bb) $stop; + bb = new; + b = bb; + i = $cast(bbo, b); + if (i != 1) $stop; + if (b != bb) $stop; - bb = null; - b = bb; - i = $cast(bbo, b); - if (i != 1) $stop; - if (b != bb) $stop; + bb = null; + b = bb; + i = $cast(bbo, b); + if (i != 1) $stop; + if (b != bb) $stop; - bb = BasedB::getBasedB(1); - b = bb; - i = $cast(bbo, b); - if (i != 1) $stop; - if (b != bb) $stop; + bb = BasedB::getBasedB(1); + b = bb; + i = $cast(bbo, b); + if (i != 1) $stop; + if (b != bb) $stop; - bb = new; - b = bb; - bao = ba; - i = $cast(bao, b); - if (i != 0) $stop; - if (bao != ba) $stop; // Unchanged + bb = new; + b = bb; + bao = ba; + i = $cast(bao, b); + if (i != 0) $stop; + if (bao != ba) $stop; // Unchanged - $write("*-* All Finished *-*\n"); - $finish; - end + $write("*-* All Finished *-*\n"); + $finish; + end endmodule diff --git a/test_regress/t/t_castdyn_run_bad.out b/test_regress/t/t_castdyn_run_bad.out index 3df579223..4cc3bde3a 100644 --- a/test_regress/t/t_castdyn_run_bad.out +++ b/test_regress/t/t_castdyn_run_bad.out @@ -1,3 +1,3 @@ -[0] %Error: t_castdyn_run_bad.v:32: Assertion failed in top.t: 'assert' failed. -%Error: t/t_castdyn_run_bad.v:32: Verilog $stop +[0] %Error: t_castdyn_run_bad.v:35: Assertion failed in top.t: '$cast' failed. +%Error: t/t_castdyn_run_bad.v:35: Verilog $stop Aborting... diff --git a/test_regress/t/t_castdyn_run_bad.v b/test_regress/t/t_castdyn_run_bad.v index 26f8b1de1..2d657b6b8 100644 --- a/test_regress/t/t_castdyn_run_bad.v +++ b/test_regress/t/t_castdyn_run_bad.v @@ -12,26 +12,29 @@ class ExbaseB extends Base; endclass module t; - int i; + int i; - Base b; - ExbaseA ba, ba1; - ExbaseB bb, bb1; + Base b; + ExbaseA ba, ba1; + ExbaseB bb, bb1; - initial begin - ba = new; - b = ba; - i = $cast(ba1, b); - if (i != 1) $stop; - $cast(ba1, b); // ok at runtime + initial begin + ba = new; + b = ba; + i = $cast(ba1, b); + if (i != 1) $stop; + $cast(ba1, b); // ok at runtime - bb = new; - b = bb; - i = $cast(ba1, b); - if (i != 0) $stop; - $cast(ba1, b); + b = null; + $cast(ba1, b); // no failure on null - $write("*-* All Finished *-*\n"); - $finish; - end + bb = new; + b = bb; + i = $cast(ba1, b); + if (i != 0) $stop; + $cast(ba1, b); // <-- Bad $cast task + + $write("*-* All Finished *-*\n"); + $finish; + end endmodule