[llvm-bugs] [Bug 51005] New: [llvm-cov] wrong coverage with return statement

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 7 00:56:36 PDT 2021


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

            Bug ID: 51005
           Summary: [llvm-cov] wrong coverage with return statement
           Product: Runtime Libraries
           Version: 12.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: byone.heng at gmail.com
                CC: llvm-bugs at lists.llvm.org

$./clang -v                                                                     
clang version 12.0.0 (https://github.com/llvm/llvm-project.git
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 short int true_var = 1;
const int false_var = 0;
#if defined (__i386__) || defined (__x86_64__)
#define ASM_STR "btsl $1, %0; jc %l[lab]"
#endif
__attribute__((noinline, noclone)) int
foo (int a, int b)
{
  if (a)
    return -3;
#ifdef ASM_STR
  asm volatile goto (ASM_STR : : "m" (b) : "memory" : lab);
  if( true_var > 0 )
  {
  return 0;
  }
lab:
#endif
  return 0;
}
int
bar (int a, int b)
{
  if (a)
    return -3;
#ifdef ASM_STR
  asm volatile goto (ASM_STR : : "m" (b) : "memory" : lab);
  return 0;
lab:
#endif
  return 0;
}
int
main ()
{
  if (foo (1, 0) != -3
      || foo (0, 3) != 0
      || foo (1, 0) != -3
      || foo (0, 0) != 0
      || bar (1, 0) != -3
      || bar (0, 3) != 0
      || bar (1, 0) != -3
      || bar (0, 0) != 0)
    __builtin_abort ();
  return 0;
}

$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 short int true_var = 1;
    5|       |const int false_var = 0;
    6|       |
    7|       |#if defined (__i386__) || defined (__x86_64__)
    8|       |#define ASM_STR "btsl $1, %0; jc %l[lab]"
    9|       |#endif
   10|       |
   11|       |__attribute__((noinline, noclone)) int
   12|       |foo (int a, int b)
   13|      4|{
   14|      4|  if (a)
   15|      2|    return -3;
   16|      2|#ifdef ASM_STR
   17|      2|  asm volatile goto (ASM_STR : : "m" (b) : "memory" : lab);
   18|      2|  if( true_var > 0 )
   19|      1|  {
   20|      1|  return 0;
   21|      1|  }
   22|      1|lab:
   23|      1|#endif
   24|      1|  return 0;
   25|      2|}
   26|       |
   27|       |int
   28|       |bar (int a, int b)
   29|      4|{
   30|      4|  if (a)
   31|      2|    return -3;
   32|      2|#ifdef ASM_STR
   33|      2|  asm volatile goto (ASM_STR : : "m" (b) : "memory" : lab);
   34|      2|  return 0;
   35|      1|lab:
   36|      1|#endif
   37|      1|  return 0;
   38|      2|}
   39|       |
   40|       |int
   41|       |main ()
   42|      1|{
   43|      1|  if (foo (1, 0) != -3
   44|      1|      || foo (0, 3) != 0
   45|      1|      || foo (1, 0) != -3
   46|      1|      || foo (0, 0) != 0
   47|      1|      || bar (1, 0) != -3
   48|      1|      || bar (0, 3) != 0
   49|      1|      || bar (1, 0) != -3
   50|      1|      || bar (0, 0) != 0)
   51|      0|    __builtin_abort ();
   52|      1|  return 0;
   53|      1|}

Line 20 should be executed twice

-- 
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/20210707/3a662176/attachment.html>


More information about the llvm-bugs mailing list