[llvm-bugs] [Bug 48278] New: llvm-cov: marco in if statement leads to wrong code coverage

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 23 20:41:07 PST 2020


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

            Bug ID: 48278
           Summary: llvm-cov: marco in if statement leads to wrong code
                    coverage
           Product: Runtime Libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at nju.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ cat test.c
#define MK(A) (A << 2)

int foo(int q)
{
  if (q != MK(2))
    return 0;
  else
    return 1;
}

void main()
{
  int q = MK(2);
  int r = foo(q);
  printf("%d\n", r);
}

$ clang -O0 -w -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.c.lcov; cat test.c.lcov
1
    1|      2|#define MK(A) (A << 2)
    2|       |
    3|       |int foo(int q)
    4|      1|{
    5|      1|  if (q != MK(2))
    6|      1|    return 0;
    7|      1|  else
    8|      1|    return 1;
    9|      1|}
   10|       |
   11|       |void main()
   12|      1|{
   13|      1|  int q = MK(2);
   14|      1|  int r = foo(q);
   15|      1|  printf("%d\n", r);
   16|      1|}

#################
Line #6 is wrongly marked as executed. When debug this program, Line#6 is not
hit by LLDB.


$ clang --version; llvm-cov --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
LLVM (http://llvm.org/):
  LLVM version 11.0.0
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake

-- 
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/20201124/1cf326ed/attachment.html>


More information about the llvm-bugs mailing list