[llvm-bugs] [Bug 38821] New: Invalid counters with a switch statement

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 4 02:59:57 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38821

            Bug ID: 38821
           Summary: Invalid counters with a switch statement
           Product: compiler-rt
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: profile
          Assignee: cdenizet at mozilla.com
          Reporter: cdenizet at mozilla.com
                CC: llvm-bugs at lists.llvm.org, mcastelluccio at mozilla.com

Here is the C code:
int main(void)
{
  int i = 22;

  switch (i) {
    case 7:
      break;

    case 22:
      i = 7;
      break;

    case 42:
      break;
  }

  return 0;
}

The .c.gcov is:
        -:    0:Source:sl.c
        -:    0:Graph:sl.gcno
        -:    0:Data:sl.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:int main(void)
        -:    2:{
        2:    3:  int i = 22;
        -:    4:
        2:    5:  switch (i) {
        -:    6:    case 7:
    #####:    7:      break;
        -:    8:
        -:    9:    case 22:
        1:   10:      i = 7;
        1:   11:      break;
        -:   12:
        -:   13:    case 42:
    #####:   14:      break;
        -:   15:  }
        -:   16:
        1:   17:  return 0;
        -:   18:}

Notice the 2 on lines 3 and 5.
And a gcda dump gives:
===== main (0) @ sl.c:1
Block : 0 Counter : 1
        Destination Edges : 1 (1), 
Block : 1 Counter : 2
        Source Edges : 0 (1), 
        Destination Edges : 2 (0), 3 (1), 4 (0), 5 (1), 
        Lines : 3,5,
Block : 2 Counter : 0
        Source Edges : 1 (0), 
        Destination Edges : 5 (0), 
        Lines : 7,
Block : 3 Counter : 1
        Source Edges : 1 (1), 
        Destination Edges : 5 (1), 
        Lines : 10,11,
Block : 4 Counter : 0
        Source Edges : 1 (0), 
        Destination Edges : 5 (0), 
        Lines : 14,
Block : 5 Counter : 1
        Source Edges : 1 (1), 2 (0), 3 (1), 4 (0), 
        Destination Edges : 6 (1), 
        Lines : 17,
Block : 6 Counter : 1
        Source Edges : 5 (1), 
File 'sl.c'
Lines executed:71.43% of 7
sl.c:creating 'sl.c.gcov'

The block 1 has a branch to block 5, but this branch is not taken so the
counter for 1->5 must be 0.

-- 
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/20180904/a7d5f3e1/attachment.html>


More information about the llvm-bugs mailing list