[PATCH] D157110: llvm-cov: __cxx_global_var_init functions disrupt coverage

Oleksii Odynochenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 08:29:56 PDT 2023


tenta4 created this revision.
tenta4 added reviewers: bogner, dnovillo.
tenta4 added projects: All, LLVM.
Herald added subscribers: dmgreen, hiraditya.
tenta4 requested review of this revision.
Herald added a subscriber: llvm-commits.

My llvm-cov reports show phantom executable lines in some cases.
It's 100 reproducible.
It appears on random places (see attached images), even for unexistent lines.
My investigations show that it appears on __cxx_global_var_init* processing.

For example here is an output

      -:  397:/*------------------------------------------------------------------------------------------------*/
      -:  398:template<typename T>
  #####:  399:void putGlmVec(boost::property_tree::ptree* const  parameter_node,
      -:  400:               boost::any                   const& value,
  #####:  401:               std::string                  const& type)
      -:  402:/*------------------------------------------------------------------------------------------------*/
      -:  403:{

And here is debug data for this case

  > gdb --args llvm-project/build/bin/llvm-cov gcov ./src/Settings/PersistenceAdapterSample/src/CMakeFiles/C_MXR_Settings_PersistenceAdapterSample_Base_Impl.dir/CPersistenceAdapterImpl.cpp.gcno
  (gdb) b GCOV.cpp:689
  (gdb) condition 1 lineNum==401
  (gdb) r
  (gdb) p f.Name
  $7 = {static npos = 18446744073709551615, Data = 0x7ffff784faa0 "__cxx_global_var_init.44", Length = 24}
  (gdb) p lineNum 
  $8 = 401
  (gdb) p f.blocks[4]->lines[0]
  $29 = (unsigned int &) @0x1aa0300: 401
  (gdb) p f.startLine
  $9 = 0
  (gdb) p f.startColumn 
  $10 = 0
  (gdb) p f.endLine 
  $11 = 0

It's definitely bug. For project with ~100K lines I have many similar cases.
Probably, my patch is not the best way to fix it and there are better ways to filter such functions.
If so, please direct me.


https://reviews.llvm.org/D157110

Files:
  llvm/lib/ProfileData/GCOV.cpp


Index: llvm/lib/ProfileData/GCOV.cpp
===================================================================
--- llvm/lib/ProfileData/GCOV.cpp
+++ llvm/lib/ProfileData/GCOV.cpp
@@ -677,6 +677,9 @@
   for (const GCOVBlock &b : f.blocksRange()) {
     if (b.lines.empty())
       continue;
+    if (f.startLine == 0 && f.startColumn == 0 && f.endLine == 0)
+      // skipping automatically-generated functions
+      continue;
     uint32_t maxLineNum = *std::max_element(b.lines.begin(), b.lines.end());
     if (maxLineNum >= si.lines.size())
       si.lines.resize(maxLineNum + 1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157110.547214.patch
Type: text/x-patch
Size: 579 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230804/d6009463/attachment.bin>


More information about the llvm-commits mailing list