diff --git a/include/verilated_cov.h b/include/verilated_cov.h index 5620c03b3..d047be195 100644 --- a/include/verilated_cov.h +++ b/include/verilated_cov.h @@ -63,14 +63,16 @@ class VerilatedCovImp; /// for (int i = 0; i < 10; ++i) m_cases[i] = 0; /// // Insert /// for (int i = 0; i < 10; ++i) -/// VL_COVER_INSERT(&m_cases[i], "comment", "Coverage Case", "i", cvtToNumStr(i)); +/// VL_COVER_INSERT(covp, name(), &m_cases[i], "comment", "Coverage Case", +/// "i", cvtToNumStr(i)); /// } -#define VL_COVER_INSERT(covcontextp, countp, ...) \ +#define VL_COVER_INSERT(covcontextp, name, countp, ...) \ do { \ - covcontextp->_inserti(countp); \ - covcontextp->_insertf(__FILE__, __LINE__); \ - covcontextp->_insertp("hier", name(), __VA_ARGS__); \ + auto const ccontextp = covcontextp; \ + ccontextp->_inserti(countp); \ + ccontextp->_insertf(__FILE__, __LINE__); \ + ccontextp->_insertp("hier", name, __VA_ARGS__); \ } while (false) //============================================================================= diff --git a/src/V3EmitCImp.cpp b/src/V3EmitCImp.cpp index 3daa693cd..f24c79a01 100644 --- a/src/V3EmitCImp.cpp +++ b/src/V3EmitCImp.cpp @@ -324,13 +324,14 @@ class EmitCImp final : EmitCFunc { // Used for second++ instantiation of identical bin puts("if (!enable) count32p = &fake_zero_count;\n"); puts("*count32p = 0;\n"); - puts("VL_COVER_INSERT(vlSymsp->_vm_contextp__->coveragep(), count32p,"); + puts("VL_COVER_INSERT(vlSymsp->_vm_contextp__->coveragep(), VerilatedModule::name(), " + "count32p,"); puts(" \"filename\",filenamep,"); puts(" \"lineno\",lineno,"); puts(" \"column\",column,\n"); // Need to move hier into scopes and back out if do this // puts( "\"hier\",std::string{vlSymsp->name()} + hierp,"); - puts("\"hier\",std::string{name()} + hierp,"); + puts("\"hier\",std::string{VerilatedModule::name()} + hierp,"); puts(" \"page\",pagep,"); puts(" \"comment\",commentp,"); puts(" (linescovp[0] ? \"linescov\" : \"\"), linescovp);\n"); diff --git a/test_regress/t/t_cover_lib_c.cpp b/test_regress/t/t_cover_lib_c.cpp index 2e29e0214..6afe305c6 100644 --- a/test_regress/t/t_cover_lib_c.cpp +++ b/test_regress/t/t_cover_lib_c.cpp @@ -36,7 +36,7 @@ void hier_insert(VerilatedCovContext* covContextp, uint64_t* countp, const char* const char* peri) { // This needs to be a function at one line number so all of the // line numbers for coverage are constant, otherwise instances won't combine. - VL_COVER_INSERT(covContextp, countp, "hier", hierp, "per_instance", peri); + VL_COVER_INSERT(covContextp, name(), countp, "hier", hierp, "per_instance", peri); } int main() { @@ -45,9 +45,9 @@ int main() { VerilatedCovContext* covContextp = Verilated::defaultContextp()->coveragep(); - VL_COVER_INSERT(covContextp, &covers[0], "comment", "kept_one"); - VL_COVER_INSERT(covContextp, &coverw[0], "comment", "kept_two"); - VL_COVER_INSERT(covContextp, &coverw[1], "comment", "lost_three"); + VL_COVER_INSERT(covContextp, name(), &covers[0], "comment", "kept_one"); + VL_COVER_INSERT(covContextp, name(), &coverw[0], "comment", "kept_two"); + VL_COVER_INSERT(covContextp, name(), &coverw[1], "comment", "lost_three"); hier_insert(covContextp, &coverw[2], "top.a0.pi", "0"); hier_insert(covContextp, &coverw[3], "top.a1.pi", "0"); diff --git a/test_regress/t/t_name_collision.pl b/test_regress/t/t_name_collision.pl index b46d46042..0723e1873 100755 --- a/test_regress/t/t_name_collision.pl +++ b/test_regress/t/t_name_collision.pl @@ -11,6 +11,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(simulator => 1); compile( + verilator_flags2 => ['--coverage'], ); execute(