[llvm-bugs] [Bug 51266] New: [LLVM-COV] Code after "va_arg" was wrongly marked as executed.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 29 06:33:21 PDT 2021


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

            Bug ID: 51266
           Summary: [LLVM-COV] Code after "va_arg" was wrongly marked as
                    executed.
           Product: Runtime Libraries
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: cnwy1996 at outlook.com
                CC: llvm-bugs at lists.llvm.org

$ clang -v
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wangyang/llvm-project/build/bin
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
Selected multilib: .;@m64

$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void __attribute__((noinline, noclone)) bar(int x, va_list *ap) {
  if (ap) {
    int i;
    for (i = 0; i < 10; i++)
      if (i != va_arg(*ap, int))
        __builtin_abort();
    if (va_arg(*ap, double) != 0.5)
      __builtin_abort();
  }
}

void __attribute__((noinline, noclone)) foo(int x, ...) {
  va_list ap;
  int n;

  va_start(ap, x);
  n = va_arg(ap, int);
  bar(x, (va_list *)((n == 0) ? ((void *)0) : &ap));
  va_end(ap);
}

int main() {
  foo(100, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0.5);
  return 0;
}



$ clang -w -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
    1|       |#include <stdio.h>
    2|       |#include <stdlib.h>
    3|       |#include <stdarg.h>
    4|       |
    5|      1|void __attribute__((noinline, noclone)) bar(int x, va_list *ap) {
    6|      1|  if (ap) {
    7|      1|    int i;
    8|     11|    for (i = 0; i < 10; i++)
    9|     10|      if (i != va_arg(*ap, int))
   10|     10|        __builtin_abort();
   11|      1|    if (va_arg(*ap, double) != 0.5)
   12|      0|      __builtin_abort();
   13|      1|  }
   14|      1|}
   15|       |
   16|      1|void __attribute__((noinline, noclone)) foo(int x, ...) {
   17|      1|  va_list ap;
   18|      1|  int n;
   19|      1|
   20|      1|  va_start(ap, x);
   21|      1|  n = va_arg(ap, int);
   22|      1|  bar(x, (va_list *)((n == 0) ? ((void *)0) : &ap));
   23|      1|  va_end(ap);
   24|      1|}
   25|       |
   26|      1|int main() {
   27|      1|  foo(100, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0.5);
   28|      1|  return 0;
   29|      1|}

Line 10 was never executed.

-- 
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/20210729/69d67308/attachment-0001.html>


More information about the llvm-bugs mailing list