[llvm-bugs] [Bug 37085] New: [LLCM-COV] Wrong coverage with a defined marco in if statement

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 11 00:44:35 PDT 2018


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

            Bug ID: 37085
           Summary: [LLCM-COV] Wrong coverage with a defined marco in if
                    statement
           Product: Runtime Libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at nju.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ clang -v
clang version 7.0.0- (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ cat small.c
#define LENGTH 4
int foo (int n)
{
  int i = 0;
  do {
    if (n > LENGTH)
      i++;
    n = 0;
 } while (n > 0);

 return 0;
}

int main() {
  foo (4);
  return 0;
}

$ clang -O0 -g -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.gcov; cat small.gcov
    1|      1|#define LENGTH 4
    2|       |int foo (int n)
    3|      1|{
    4|      1|  int i = 0;
    5|      1|  do {
    6|      1|    if (n > LENGTH)
    7|      1|      i++;
    8|      1|    n = 0;
    9|      1| } while (n > 0);
   10|      1|
   11|      1| return 0;
   12|      1|}
   13|       |
   14|      1|int main() {
   15|      1|  foo (4);
   16|      1|  return 0;
   17|      1|}


Line #7 is wrongly marked as executed. Since LENGTH is 4, and foo(4) is called.
therefore, Line #7 should be not executed. 
When replacing LENGTH with 4, the coverage is correrct.

-- 
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/20180411/bc6dca79/attachment.html>


More information about the llvm-bugs mailing list