<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - llvm-cov gcov should merge results for common files (commonly headers)"
   href="https://bugs.llvm.org/show_bug.cgi?id=33981">33981</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-cov gcov should merge results for common files (commonly headers)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jon.grimm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Whenever common source files are found across multilple .gcda files their
results should be merged to give to the total view of coverage, before emitting
a .gcov file and summary.  Otherwise the gcov file for a common file contains
only the results of the last gcda processed. :/

gcov works this way:
  <a href="https://gcc.gnu.org/ml/gcc-patches/2007-06/msg00423.html">https://gcc.gnu.org/ml/gcc-patches/2007-06/msg00423.html</a>   (note, became
default behavior, not behind a flag). 

Discovered when I was playing with getting llvm-cov gcov working with ccan and
found it was depending on this behavior (and noticed i was getting really
crappy coverage for some files.. since only contained result of whatever test
ran last). 

Trivial test case to show the problem:   

// f1.c:
#include "comm.h"

int main (void)
{
        common(1);
        return 0;
}

// f2.c:
#include "comm.h"

int main (void)
{
        common(2);
        return 0;
}

// comm.h:
#include <stdio.h>

void common (int n)
{
        switch(n) {
        case 1:
                printf("Came from f1\n");
                break;
        case 2:
                printf("Came from f2\n");
                break;
        default:
                printf("Not sure: %d\n", n);
        }

}

My two test cases are f1 and f2.  I want to be able to see the coverage for the
code in comm.h shared by each of these testcases.  

  $ clang -fprofile-arcs -ftest-coverage -g f1.c -o f1
  $ clang -fprofile-arcs -ftest-coverage -g f2.c -o f2
  $ ./f1
  Came from f1
  $ ./f2
  Came from f2
  $ llvm-cov gcov f1.c f2.c
  File 'f1.c'
  Lines executed:100.00% of 2
  f1.c:creating 'f1.c.gcov'

  File './comm.h'
  Lines executed:50.00% of 8
  ./comm.h:creating 'comm.h.gcov'

  File 'f2.c'
  Lines executed:100.00% of 2
  f2.c:creating 'f2.c.gcov'

  File './comm.h'
  Lines executed:50.00% of 8
  ./comm.h:creating 'comm.h.gcov'



Note that comm.h is found twice, and the corresponding gcov file only contains
the results of the second testcase (f2 in this example). 


With gcov you'll instead get: 

  $ gcov f1.c f2.c
  File 'f1.c'
  Lines executed:100.00% of 3
  Creating 'f1.c.gcov'

  File 'comm.h'
  Lines executed:87.50% of 8
  Creating 'comm.h.gcov'

  File 'f2.c'
  Lines executed:100.00% of 3
  Creating 'f2.c.gcov'

  Lines executed:92.86% of 14


Note how there is a single gcov output that shows the collective results of the
two testcases (and the total Lines executed summary at the end is nice too) 
and can also be verified in the gcov file: 

  $ cat comm.h.gcov
        -:    0:Source:comm.h
        -:    0:Programs:2
        -:    1:// comm.h:
        -:    2:#include <stdio.h>
        -:    3:
        2:    4:void common (int n)
        -:    5:{
        2:    6:        switch(n) {
        -:    7:        case 1:
        1:    8:                printf("Came from f1\n");
        1:    9:                break;
        -:   10:        case 2:
        1:   11:                printf("Came from f2\n");
        1:   12:                break;
        -:   13:        default:
    #####:   14:                printf("Not sure: %d\n", n);
        -:   15:        }
        -:   16:                        
        2:   17:}


Thanks!!</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>