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

            Bug ID: 101357
           Summary: the coverage of a return statement goes wrong
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: byone.heng at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$./gcc -v                                                                       
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/home/x/project/gcc/build/install/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/x/project/gcc/build/install
--enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20210105 (experimental) (GCC)

$cat test.c
const int true_var = 1;
static const unsigned long int false_var = 0;
extern void abort (void);
typedef int __attribute__((vector_size (32))) m256i;
__attribute__((noinline, noclone)) void
foo (int *x, m256i *y)
{
  asm volatile ("" : : "r" (x), "r" (y) : "memory");
}
__attribute__((noinline, noclone)) int
bar (int x)
{
  if (x > 20)
    return 24;
  m256i i;
  foo (__builtin_alloca (x), &i);
  return 128;
}
__attribute__((noinline, noclone)) int
baz (int d0, int d1, int d2, int d3, int d4, int d5, int x)
{
  if (x > 20)
    return 24;
  m256i i;
  d0 += d1 + d2 + d3 + d4 + d5; d1 += d0;
  foo (__builtin_alloca (x), &i);
  if( true_var > 0 )
  {
  return 128;
  }
}
int
main ()
{
  if (bar (22) != 24 || bar (20) != 128)
    abort ();
#ifdef __x86_64__
  register long long r10 __asm__ ("r10") = 0xdeadbeefdeadbeefULL;
  asm volatile ("" : "+r" (r10));
#endif
  if (baz (0, 0, 0, 0, 0, 0, 22) != 24 || baz (0, 0, 0, 0, 0, 0, 20) != 128)
    abort ();
  return 0;
}


$gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov

        -:    5:const int true_var = 1;
        -:    6:static const unsigned long int false_var = 0;
        -:    7:
        -:    8:extern void abort (void);
        -:    9:
        -:   10:typedef int __attribute__((vector_size (32))) m256i;
        -:   11:
        -:   12:__attribute__((noinline, noclone)) void
        2:   13:foo (int *x, m256i *y)
        -:   14:{
        2:   15:  asm volatile ("" : : "r" (x), "r" (y) : "memory");
        2:   16:}
        -:   17:
        -:   18:__attribute__((noinline, noclone)) int
        2:   19:bar (int x)
        -:   20:{
        2:   21:  if (x > 20)
        1:   22:    return 24;
        -:   23:  m256i i;
        1:   24:  foo (__builtin_alloca (x), &i);
        1:   25:  return 128;
        -:   26:}
        -:   27:
        -:   28:__attribute__((noinline, noclone)) int
        2:   29:baz (int d0, int d1, int d2, int d3, int d4, int d5, int x)
        -:   30:{
        2:   31:  if (x > 20)
        2:   32:    return 24;
        -:   33:  m256i i;
        1:   34:  d0 += d1 + d2 + d3 + d4 + d5; d1 += d0;
        1:   35:  foo (__builtin_alloca (x), &i);
        1:   36:  if( true_var > 0 )
        -:   37:  {
        1:   38:  return 128;
        -:   39:  }
    #####:   40:}
        -:   41:
        -:   42:int
        1:   43:main ()
        -:   44:{
        1:   45:  if (bar (22) != 24 || bar (20) != 128)
    #####:   46:    abort ();
        -:   47:#ifdef __x86_64__
        1:   48:  register long long r10 __asm__ ("r10") =
0xdeadbeefdeadbeefULL;
        1:   49:  asm volatile ("" : "+r" (r10));
        -:   50:#endif
        1:   51:  if (baz (0, 0, 0, 0, 0, 0, 22) != 24 || baz (0, 0, 0, 0, 0,
0, 20) != 128)
    #####:   52:    abort ();
        1:   53:  return 0;
        -:   54:}

Line 32 should be executed one time.

Reply via email to