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>
This commit is contained in:
Matthew Ballance 2026-03-05 14:28:20 +00:00
parent a3a456779d
commit dda0405fce
1 changed files with 5 additions and 0 deletions

View File

@ -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<int>(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);