Skip to content

Commit

Permalink
Fix ZERODLY to not warn on 'wait(0)'.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsnyder committed Sep 15, 2023
1 parent 2fbd41e commit 10c1653
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Verilator 5.015 devel
* Fix reference to extended class in parameterized class (#4466).
* Fix display %x formatting of real.
* Fix mis-warning on #() in classes' own functions.
* Fix ZERODLY to not warn on 'wait(0)'.


Verilator 5.014 2023-08-06
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1990,11 +1990,15 @@ List Of Warnings

.. code-block:: sv
wait(0); // Blocks forever
wait(1); // Blocks forever
Warns that a `wait` statement awaits a constant condition, which means it
either blocks forever or never blocks.

As a special case `wait(0)` with the literal constant `0` (as opposed to
something that elaborates to zero), does not warn, as it is presumed the
code is making the intent clear.


.. option:: WIDTH

Expand Down
11 changes: 11 additions & 0 deletions src/V3LinkParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,17 @@ class LinkParseVisitor final : public VNVisitor {
iterateChildren(nodep);
}
}
void visit(AstWait* nodep) override {
cleanFileline(nodep);
iterateChildren(nodep);
if (nodep->condp()->isZero()) {
// Special case "wait(0)" we won't throw WAITCONST as user wrote
// it that way with presumed intent - UVM does this.
FileLine* const newfl = nodep->fileline();
newfl->warnOff(V3ErrorCode::WAITCONST, true);
nodep->fileline(newfl);
}
}
void visit(AstWhile* nodep) override {
cleanFileline(nodep);
VL_RESTORER(m_insideLoop);
Expand Down
4 changes: 3 additions & 1 deletion src/V3Timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,9 @@ class TimingControlVisitor final : public VNVisitor {
AstNodeExpr* const condp = V3Const::constifyEdit(nodep->condp()->unlinkFrBack());
auto* const constp = VN_CAST(condp, Const);
if (constp) {
condp->v3warn(WAITCONST, "Wait statement condition is constant");
if (!nodep->fileline()->warnIsOff(V3ErrorCode::WAITCONST)) {
condp->v3warn(WAITCONST, "Wait statement condition is constant");
}
if (constp->isZero()) {
// We have to await forever instead of simply returning in case we're deep in a
// callstack
Expand Down
3 changes: 0 additions & 3 deletions test_regress/t/t_lint_wait_bad.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
%Warning-WAITCONST: t/t_timing_wait1.v:54:14: Wait statement condition is constant
54 | wait(0 < 1) $write("*-* All Finished *-*\n");
| ^
%Warning-WAITCONST: t/t_timing_wait1.v:58:17: Wait statement condition is constant
58 | initial wait(0) $stop;
| ^
%Warning-WAITCONST: t/t_timing_wait1.v:59:19: Wait statement condition is constant
59 | initial wait(1 == 0) $stop;
| ^~
Expand Down
2 changes: 1 addition & 1 deletion test_regress/t/t_timing_wait1.v
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module t;
$finish;
end

initial wait(0) $stop;
initial wait(0) $stop; // Note this doesn't give WAITCONST
initial wait(1 == 0) $stop;

initial #12 $stop; // timeout
Expand Down

0 comments on commit 10c1653

Please sign in to comment.