[llvm-bugs] [Bug 45844] New: llvm-cov: macro leads to wrong code coverage

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 8 09:28:36 PDT 2020


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

            Bug ID: 45844
           Summary: llvm-cov: macro leads to wrong code coverage
           Product: Runtime Libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at hust.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ clang --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


$ clang -O0 -fcoverage-mapping -fprofile-instr-generate=small.profraw small.c;
./a.out; llvm-profdata merge small.profraw -o small.profdata; llvm-cov show
a.out -instr-profile=small.profdata small.c > small.c.lcov; cat small.c.lcov
    1|      1|#define INT_MIN (-__INT_MAX__ - 1)
    2|       |
    3|      1|int f(unsigned int u) {
    4|      1|  return (-(int)(u-1U))-1;
    5|      1|}
    6|       |
    7|      1|int main () {
    8|      1|  if(f(__INT_MAX__+1U) != INT_MIN)
    9|      1|    return 0;
   10|      1|  return 1;
   11|      1|}

Line #9 is wrongly marked as executed. This line is not executed in practice as
in lldb this line is not reached as follows:
$ clang -g small.c; lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Decov/a.out' (x86_64).
(lldb) b 9
Breakpoint 1: where = a.out`main + 36 at small.c:9:5, address =
0x0000000000401154
(lldb) run
Process 405847 launched: '/home/yibiao/Decov/a.out' (x86_64)
Process 405847 exited with status = 1 (0x00000001)

$ cat small.c
#define INT_MIN (-__INT_MAX__ - 1)

int f(unsigned int u) {
  return (-(int)(u-1U))-1;
}

int main () {
  if(f(__INT_MAX__+1U) != INT_MIN)
    return 0;
  return 1;
}

-- 
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/20200508/12cbcff3/attachment.html>


More information about the llvm-bugs mailing list