[llvm-bugs] [Bug 48795] New: llvm-cov: wrong coverage for statement with nested conditional operator

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 18 19:28:32 PST 2021


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

            Bug ID: 48795
           Summary: llvm-cov: wrong coverage for statement with nested
                    conditional operator
           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

Consider this case:
...
$ cat small.c
int main()
{
    int r = 0, z = 1;
    for (int i = 0; i < 5; i++) {
        r = (z * z > 4) ? (i < r ? i : r) : r;
        z++;
    }
    return r;
}
...


...
$ clang -O0 -w -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|       |int main()
    2|      1|{
    3|      1|    int r = 0, z = 1;
    4|      6|    for (int i = 0; i < 5; i++) {
    5|      3|        r = (z * z > 4) ? (i < r ? i : r) : r;
    6|      5|        z++;
    7|      5|    }
    8|      1|    return r;
    9|      1|}
...

We can found that Line 5 is executed 3 times. The expected output should be 5. 


...
$ clang --version
Ubuntu clang version
12.0.0-++20210117052627+ed396212da41-1~exp1~20210117163329.287
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

-- 
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/20210119/6a3075e7/attachment-0001.html>


More information about the llvm-bugs mailing list