From cf7e3f791a21904c387235de5add20bcf7bae3c5 Mon Sep 17 00:00:00 2001 From: Joshua Leahy <36183+jleahy@users.noreply.github.com> Date: Mon, 29 Jun 2026 15:56:59 +0100 Subject: [PATCH] Fix covergroups without --coverage (#7848) (#7849) Fixes #7848. --- docs/CONTRIBUTORS | 1 + include/verilated_covergroup.cpp | 9 +++++++-- src/V3EmitCHeaders.cpp | 3 ++- src/V3EmitCModel.cpp | 3 ++- src/V3Global.cpp | 3 ++- .../t/t_covergroup_cross_no_coverage.py | 20 +++++++++++++++++++ .../t/t_covergroup_option_no_coverage.py | 20 +++++++++++++++++++ 7 files changed, 54 insertions(+), 5 deletions(-) create mode 100755 test_regress/t/t_covergroup_cross_no_coverage.py create mode 100755 test_regress/t/t_covergroup_option_no_coverage.py diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 10db04fcc..f0e8b1c98 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -146,6 +146,7 @@ Jose Loyola Josep Sans Joseph Nwabueze Josh Redford +Joshua Leahy Julian Carrier Julian Daube Julie Schwartz diff --git a/include/verilated_covergroup.cpp b/include/verilated_covergroup.cpp index 6dc7006f1..c872d5557 100644 --- a/include/verilated_covergroup.cpp +++ b/include/verilated_covergroup.cpp @@ -14,7 +14,8 @@ /// \file /// \brief Verilated functional-coverage collection runtime implementation /// -/// Compiled and linked when "verilator --coverage" is used with covergroups. +/// Linked when covergroups are present. The coverage-database registration +/// is compiled only with "verilator --coverage". /// //============================================================================= @@ -22,7 +23,9 @@ #include "verilated_covergroup.h" -#include "verilated_cov.h" +#if VM_COVERAGE +# include "verilated_cov.h" +#endif void VlCoverpoint::init(const char* hier, uint32_t atLeast, int nBins) { m_hier = hier; @@ -54,6 +57,7 @@ std::string VlCoverpoint::binName(int i) const { return name; } +#if VM_COVERAGE void VlCoverpoint::registerBins(VerilatedCovContext* covcontextp, const char* page) { for (int i = 0; i < binCount(); ++i) { const VlCovNamer& nm = namerFor(i); @@ -76,3 +80,4 @@ void VlCoverpoint::registerBins(VerilatedCovContext* covcontextp, const char* pa } } } +#endif // VM_COVERAGE diff --git a/src/V3EmitCHeaders.cpp b/src/V3EmitCHeaders.cpp index 2a3197112..8b2f2add0 100644 --- a/src/V3EmitCHeaders.cpp +++ b/src/V3EmitCHeaders.cpp @@ -683,7 +683,8 @@ class EmitCHeader final : public EmitCConstInit { if (v3Global.opt.mtasks()) puts("#include \"verilated_threads.h\"\n"); if (v3Global.opt.savable()) puts("#include \"verilated_save.h\"\n"); if (v3Global.opt.coverage()) puts("#include \"verilated_cov.h\"\n"); - if (v3Global.opt.coverage()) puts("#include \"verilated_covergroup.h\"\n"); + if (v3Global.opt.coverage() || v3Global.useCovergroup()) + puts("#include \"verilated_covergroup.h\"\n"); if (v3Global.usesTiming()) puts("#include \"verilated_timing.h\"\n"); if (v3Global.useRandomizeMethods()) puts("#include \"verilated_random.h\"\n"); if (v3Global.usesForce()) puts("#include \"verilated_force.h\"\n"); diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index 6ddd53e77..034b1e807 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -70,7 +70,8 @@ class EmitCModel final : public EmitCFunc { if (v3Global.opt.mtasks()) puts("#include \"verilated_threads.h\"\n"); if (v3Global.opt.savable()) puts("#include \"verilated_save.h\"\n"); if (v3Global.opt.coverage()) puts("#include \"verilated_cov.h\"\n"); - if (v3Global.opt.coverage()) puts("#include \"verilated_covergroup.h\"\n"); + if (v3Global.opt.coverage() || v3Global.useCovergroup()) + puts("#include \"verilated_covergroup.h\"\n"); if (v3Global.dpi()) puts("#include \"svdpi.h\"\n"); // Declare foreign instances up front to make C++ happy diff --git a/src/V3Global.cpp b/src/V3Global.cpp index 2e7c25fc7..3fd207be3 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -245,7 +245,8 @@ std::vector V3Global::verilatedCppFiles() { if (v3Global.opt.vpi()) result.emplace_back("verilated_vpi.cpp"); if (v3Global.opt.savable()) result.emplace_back("verilated_save.cpp"); if (v3Global.opt.coverage()) result.emplace_back("verilated_cov.cpp"); - if (v3Global.opt.coverage()) result.emplace_back("verilated_covergroup.cpp"); + if (v3Global.opt.coverage() || v3Global.useCovergroup()) + result.emplace_back("verilated_covergroup.cpp"); for (const string& base : v3Global.opt.traceSourceBases()) result.emplace_back(base + "_c.cpp"); if (v3Global.usesProbDist()) result.emplace_back("verilated_probdist.cpp"); diff --git a/test_regress/t/t_covergroup_cross_no_coverage.py b/test_regress/t/t_covergroup_cross_no_coverage.py new file mode 100755 index 000000000..699c061b8 --- /dev/null +++ b/test_regress/t/t_covergroup_cross_no_coverage.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of either the GNU Lesser General Public License Version 3 +# or the Perl Artistic License Version 2.0. +# SPDX-FileCopyrightText: 2026 Wilson Snyder +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('vlt_all') +test.top_filename = 't/t_covergroup_cross.v' + +# runs without --coverage +test.compile(verilator_flags2=['--Wno-COVERIGN']) + +test.execute() + +test.passes() diff --git a/test_regress/t/t_covergroup_option_no_coverage.py b/test_regress/t/t_covergroup_option_no_coverage.py new file mode 100755 index 000000000..5f3bb6c6d --- /dev/null +++ b/test_regress/t/t_covergroup_option_no_coverage.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of either the GNU Lesser General Public License Version 3 +# or the Perl Artistic License Version 2.0. +# SPDX-FileCopyrightText: 2026 Wilson Snyder +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('vlt') +test.top_filename = 't/t_covergroup_option.v' + +# runs without --coverage +test.compile(verilator_flags2=['--Wno-COVERIGN']) + +test.execute() + +test.passes()