https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101569

            Bug ID: 101569
           Summary: [GCOV] Wrong coverage caused by callee format.
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: njuwy at smail dot nju.edu.cn
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++
-disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC) 


$ cat test.c
#include<stdlib.h>
#include<stdio.h>
typedef unsigned char u8;
typedef unsigned long long u64;

static inline __attribute__((always_inline)) u64 __swab64p(const u64 *p) {
  return (__builtin_constant_p((u64)(*p))? 
                       (u64)(((u64)(*p) & (u64)0x00000000000000ffULL) << 56)
                       :__builtin_bswap64(*p));
}

static inline u64 wwn_to_u64(void *wwn) { return __swab64p(wwn); }

static inline u64 wwn_to_u64_copy(void *wwn) { 
return __swab64p(wwn); 
}

void __attribute__((noinline, noclone)) broken(u64 *shost) {
  u8 node_name[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  *shost = wwn_to_u64(node_name);
  *shost = wwn_to_u64_copy(node_name);
}

int main(int argc, char *argv[]) {
  u64 v;

  broken(&v);

  if (v != (u64)-1)
    __builtin_abort();

  return 0;
}

$ gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov
File 'test.c'
Lines executed:92.86% of 14
Creating 'test.c.gcov'

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:#include<stdlib.h>
        -:    2:#include<stdio.h>
        -:    3:typedef unsigned char u8;
        -:    4:typedef unsigned long long u64;
        -:    5:
        -:    6:static inline __attribute__((always_inline)) u64
__swab64p(const u64 *p) {
        -:    7:  return (__builtin_constant_p((u64)(*p))? 
        -:    8:                       (u64)(((u64)(*p) &
(u64)0x00000000000000ffULL) << 56)
        2:    9:                       :__builtin_bswap64(*p));
        -:   10:}
        -:   11:
        2:   12:static inline u64 wwn_to_u64(void *wwn) { return
__swab64p(wwn); }
        -:   13:
        1:   14:static inline u64 wwn_to_u64_copy(void *wwn) { 
        1:   15:return __swab64p(wwn); 
        -:   16:}
        -:   17:
        1:   18:void __attribute__((noinline, noclone)) broken(u64 *shost) {
        1:   19:  u8 node_name[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF};
        1:   20:  *shost = wwn_to_u64(node_name);
        1:   21:  *shost = wwn_to_u64_copy(node_name);
        1:   22:}
        -:   23:
        1:   24:int main(int argc, char *argv[]) {
        -:   25:  u64 v;
        -:   26:
        1:   27:  broken(&v);
        -:   28:
        1:   29:  if (v != (u64)-1)
    #####:   30:    __builtin_abort();
        -:   31:
        1:   32:  return 0;
        -:   33:}

Line 14 and 15 were executed once. However, when they are in one line, the
coverage becomes 2.

Reply via email to