<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] "assert" function in "else" structure has wrong coverage"
   href="https://bugs.llvm.org/show_bug.cgi?id=51267">51267</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LLVM-COV] "assert" function in "else" structure has wrong coverage
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>11.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>libprofile library
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>cnwy1996@outlook.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ clang -v
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wangyang/llvm-project/build/bin
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
Selected multilib: .;@m64

$ cat test.c
#include <assert.h>
#include <stdio.h>
#include <string.h>

static inline __attribute__((__artificial__)) void *a(char *c, const char *d,
                                                      long n) {
  return __builtin___memcpy_chk(c, d, n, __builtin_object_size(c, 0));
}
typedef struct {
  char *data;
  int len;
} sb_t;
const char __sb_slop[1];
static void inline set0(sb_t *c) {
  if (c->data != __sb_slop)
    c->data[0] = 0;
  else

    assert(c->data[0] == 0);
}
char buf[5];
sb_t l = {.data = buf, .len = 0};
void o() {
  char *data = "abcd";
  sb_t h = l;
  set0(&h);
  a(h.data, data, strlen(data));
  printf("%s\n", h.data);
  printf("%d\n", h.data == __sb_slop);
  printf("%d\n", h.data == buf);
  set0(&h);
}
int main(void) {
  o();
  return 0;
}

$ clang -w -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
abcd
0
1
    1|       |#include <assert.h>
    2|       |#include <stdio.h>
    3|       |#include <string.h>
    4|       |
    5|       |static inline __attribute__((__artificial__)) void *a(char *c,
const char *d,
    6|      1|                                                      long n) {
    7|      1|  return __builtin___memcpy_chk(c, d, n, __builtin_object_size(c,
0));
    8|      1|}
    9|       |typedef struct {
   10|       |  char *data;
   11|       |  int len;
   12|       |} sb_t;
   13|       |const char __sb_slop[1];
   14|      2|static void inline set0(sb_t *c) {
   15|      2|  if (c->data != __sb_slop)
   16|      2|    c->data[0] = 0;
   17|      2|  else
   18|      2|
   19|      2|    assert(c->data[0] == 0);
   20|      2|}
   21|       |char buf[5];
   22|       |sb_t l = {.data = buf, .len = 0};
   23|      1|void o() {
   24|      1|  char *data = "abcd";
   25|      1|  sb_t h = l;
   26|      1|  set0(&h);
   27|      1|  a(h.data, data, strlen(data));
   28|      1|  printf("%s\n", h.data);
   29|      1|  printf("%d\n", h.data == __sb_slop);
   30|      1|  printf("%d\n", h.data == buf);
   31|      1|  set0(&h);
   32|      1|}
   33|      1|int main(void) {
   34|      1|  o();
   35|      1|  return 0;
   36|      1|}


Line 17 to 19 were not executed</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>