diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index 87c26d9b5d..257b85771d 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -220,6 +220,11 @@ class CoverageVisitor final : public VNVisitor { } iterateChildren(nodep); } + void visit(AstFunc* nodep) override { + VL_RESTORER(m_state); + m_state.m_on = false; + iterateChildren(nodep); + } void visit(AstNodeProcedure* nodep) override { iterateProcedure(nodep); } void visit(AstWhile* nodep) override { iterateProcedure(nodep); } @@ -405,6 +410,10 @@ class CoverageVisitor final : public VNVisitor { void visit(AstCond* nodep) override { UINFO(4, " COND: " << nodep << endl); + if (!m_state.m_on) { + return; + } + // Current method cannot run coverage for impure statements if (!nodep->condp()->isPure()) { return;