<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] a for statement in the if statement has incorrect coverage"
   href="https://bugs.llvm.org/show_bug.cgi?id=51007">51007</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[llvm-cov] a for statement in the if statement has incorrect coverage
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Runtime Libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>libprofile library
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>byone.heng@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$./clang -v                                                                     
clang version 12.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
b6c8feb29fce39121884f7e08ec6eb0f58da3fb7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/x/project/llvm-project/build/install/bin/.
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

$cat test.c

static volatile unsigned short int true_var = 1;
static const unsigned short int false_var = 0;
extern int strcmp(const char *, const char *);
extern char *strcpy(char *, const char *);
extern void abort(void);
extern void exit(int);
void *buf[20];

void __attribute__((noinline))
sub2 (void)
{
  __builtin_longjmp (buf, 1);
}

int
main ()
{
  char *p = (char *) __builtin_alloca (20);
  strcpy (p, "test");

  if (__builtin_setjmp (buf))
    {
      if (strcmp (p, "test") != 0)
        abort ();
         exit (0);
    }

  {
    int *q = (int *) __builtin_alloca (p[2] * sizeof (int));
    int i;
    if( true_var > 0 )
    {
          for (i = 0; i < p[2]; i++)
          q[i] = 0;

          while (1)
          sub2 ();
    }
  }

——————————————————

$clang -O0 -g -fcoverage-mapping -fprofile-instr-generate=test.profraw test.c;
./a.out; llvm-profdata merge test.profraw -o test.profdata; llvm-cov show a.out
-instr-profile=test.profdata test.c > test.lcov; cat test.lcov

    4|       |static volatile unsigned short int true_var = 1;
    5|       |static const unsigned short int false_var = 0;
    6|       |
    7|       |extern int strcmp(const char *, const char *);
    8|       |extern char *strcpy(char *, const char *);
    9|       |extern void abort(void);
   10|       |extern void exit(int);
   11|       |
   12|       |void *buf[20];
   13|       |
   14|       |void __attribute__((noinline))
   15|       |sub2 (void)
   16|      1|{
   17|      1|  __builtin_longjmp (buf, 1);
   18|      1|}
   19|       |
   20|       |int
   21|       |main ()
   22|      1|{
   23|      1|  char *p = (char *) __builtin_alloca (20);
   24|       |
   25|      1|  strcpy (p, "test");
   26|       |
   27|      1|  if (__builtin_setjmp (buf))
   28|      1|    {
   29|      1|      if (strcmp (p, "test") != 0)
   30|      0|  abort ();
   31|       |
   32|      1|      exit (0);
   33|      1|    }
   34|       |
   35|      0|  {
   36|      0|    int *q = (int *) __builtin_alloca (p[2] * sizeof (int));
   37|      0|    int i;
   38|       |    
   39|      0|    if( true_var > 0 )
   40|      1|    {
   41|    116|    for (i = 0; i < p[2]; i++)
   42|    115|      q[i] = 0;
   43|       |
   44|      2|    while (1)
   45|      1|      sub2 ();
   46|      1|    }
   47|      0|  }
   48|      0|}

Line 36 and 37 were wrongly marked as unexecuted, and the coverage of line 41
should be 115.</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>