From dda0405fce36d4f3fba964ee4194e36af69450b3 Mon Sep 17 00:00:00 2001 From: Matthew Ballance Date: Thu, 5 Mar 2026 14:28:20 +0000 Subject: [PATCH] V3Covergroup: initialize bin counters to 0, not random Coverage bin counters (__Vcov_* member variables) were being initialized with VL_SCOPED_RAND_RESET_I because they are plain uint32 members with no explicit initial value. This caused 0% coverage readings at runtime when randReset != 0 (as used in CI). Fix all 5 bin counter AstVar creation sites to set an explicit valuep of AstConst(0), so V3EmitCFunc emits '= 0U' instead of VL_SCOPED_RAND_RESET_I. Affects: regular bins, default bins, array bins, transition array bins, and cross bins. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/V3Covergroup.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/V3Covergroup.cpp b/src/V3Covergroup.cpp index de6a68a52..2bef975c6 100644 --- a/src/V3Covergroup.cpp +++ b/src/V3Covergroup.cpp @@ -531,6 +531,7 @@ class FunctionalCoverageVisitor final : public VNVisitor { AstVar* const varp = new AstVar{cbinp->fileline(), VVarType::MEMBER, varName, cbinp->findUInt32DType()}; varp->isStatic(false); + varp->valuep(new AstConst{cbinp->fileline(), AstConst::WidthedValue{}, 32, 0}); m_covergroupp->addMembersp(varp); UINFO(4, " Created member variable: " << varName << " type=" << static_cast(cbinp->binsType()) @@ -566,6 +567,7 @@ class FunctionalCoverageVisitor final : public VNVisitor { AstVar* const varp = new AstVar{defBinp->fileline(), VVarType::MEMBER, varName, defBinp->findUInt32DType()}; varp->isStatic(false); + varp->valuep(new AstConst{defBinp->fileline(), AstConst::WidthedValue{}, 32, 0}); m_covergroupp->addMembersp(varp); UINFO(4, " Created default bin variable: " << varName << endl); @@ -1031,6 +1033,7 @@ class FunctionalCoverageVisitor final : public VNVisitor { AstVar* const varp = new AstVar{arrayBinp->fileline(), VVarType::MEMBER, varName, arrayBinp->findUInt32DType()}; varp->isStatic(false); + varp->valuep(new AstConst{arrayBinp->fileline(), AstConst::WidthedValue{}, 32, 0}); m_covergroupp->addMembersp(varp); UINFO(4, " Created array bin [" << index << "]: " << varName << endl); @@ -1113,6 +1116,7 @@ class FunctionalCoverageVisitor final : public VNVisitor { AstVar* const varp = new AstVar{arrayBinp->fileline(), VVarType::MEMBER, varName, arrayBinp->findUInt32DType()}; varp->isStatic(false); + varp->valuep(new AstConst{arrayBinp->fileline(), AstConst::WidthedValue{}, 32, 0}); m_covergroupp->addMembersp(varp); UINFO(4, " Created transition array bin [" << index << "]: " << varName << endl); @@ -1267,6 +1271,7 @@ class FunctionalCoverageVisitor final : public VNVisitor { AstVar* const varp = new AstVar{crossp->fileline(), VVarType::MEMBER, varName, bins[0]->findUInt32DType()}; varp->isStatic(false); + varp->valuep(new AstConst{crossp->fileline(), AstConst::WidthedValue{}, 32, 0}); m_covergroupp->addMembersp(varp); UINFO(4, " Created cross bin variable: " << varName << endl);