[llvm-bugs] [Bug 51267] New: [LLVM-COV] "assert" function in "else" structure has wrong coverage

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 29 06:47:47 PDT 2021


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

            Bug ID: 51267
           Summary: [LLVM-COV] "assert" function in "else" structure has
                    wrong coverage
           Product: Runtime Libraries
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: cnwy1996 at outlook.com
                CC: llvm-bugs at lists.llvm.org

$ 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

-- 
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/20210729/79ce8957/attachment.html>


More information about the llvm-bugs mailing list