[llvm-bugs] [Bug 33981] New: llvm-cov gcov should merge results for common files (commonly headers)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 28 10:04:43 PDT 2017


            Bug ID: 33981
           Summary: llvm-cov gcov should merge results for common files
                    (commonly headers)
           Product: new-bugs
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: jon.grimm at gmail.com
                CC: llvm-bugs at lists.llvm.org

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:
  https://gcc.gnu.org/ml/gcc-patches/2007-06/msg00423.html   (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)
        return 0;

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

int main (void)
        return 0;

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

void common (int n)
        switch(n) {
        case 1:
                printf("Came from f1\n");
        case 2:
                printf("Came from f2\n");
                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:}


You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170728/7c8f88c8/attachment.html>

More information about the llvm-bugs mailing list