[llvm-bugs] [Bug 49440] New: [LLVM-COV] "abort" function leads to incorrect coverage

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 4 05:43:53 PST 2021


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

            Bug ID: 49440
           Summary: [LLVM-COV] "abort" function leads to incorrect
                    coverage
           Product: Runtime Libraries
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          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 <limits.h>
#include <stdio.h>
extern void abort(void);

#if INT_MAX == 32767
#define LONG_CHARCONST '!\234a'
#define SHORT_CHARCONST '\234a'
#define POS_CHARCONST '\1'
#elif INT_MAX == 2147483647
#define LONG_CHARCONST '!\234abc'
#define SHORT_CHARCONST '\234abc'
#define POS_CHARCONST '\234a'
#elif INT_MAX == 9223372036854775807
#define LONG_CHARCONST '!\234abcdefg'
#define SHORT_CHARCONST '\234abcdefg'
#define POS_CHARCONST '\234a'
#else

#define LONG_CHARCONST '\234a'
#define SHORT_CHARCONST '\234a'
#define POS_CHARCONST '\1'
#endif

#if POS_CHARCONST < 0
#error Charconst incorrectly sign-extended
#endif

#if LONG_CHARCONST != SHORT_CHARCONST
#error Overly long charconst truncates wrongly for preprocessor
#endif

int main() {
  if (LONG_CHARCONST != SHORT_CHARCONST){
    abort();
  }
  if (LONG_CHARCONST != SHORT_CHARCONST)
    abort();
  if (POS_CHARCONST < 0)
    abort();
  printf("passed\n");
  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
passed
    1|       |#include <limits.h>
    2|       |#include <stdio.h>
    3|       |extern void abort(void);
    4|       |
    5|       |#if INT_MAX == 32767
    6|       |#define LONG_CHARCONST '!\234a'
    7|       |#define SHORT_CHARCONST '\234a'
    8|       |#define POS_CHARCONST '\1'
    9|       |#elif INT_MAX == 2147483647
   10|      2|#define LONG_CHARCONST '!\234abc'
   11|      2|#define SHORT_CHARCONST '\234abc'
   12|      1|#define POS_CHARCONST '\234a'
   13|       |#elif INT_MAX == 9223372036854775807
   14|       |#define LONG_CHARCONST '!\234abcdefg'
   15|       |#define SHORT_CHARCONST '\234abcdefg'
   16|       |#define POS_CHARCONST '\234a'
   17|       |#else
   18|       |
   19|       |#define LONG_CHARCONST '\234a'
   20|       |#define SHORT_CHARCONST '\234a'
   21|       |#define POS_CHARCONST '\1'
   22|       |#endif
   23|       |
   24|       |#if POS_CHARCONST < 0
   25|       |#error Charconst incorrectly sign-extended
   26|       |#endif
   27|       |
   28|       |#if LONG_CHARCONST != SHORT_CHARCONST
   29|       |#error Overly long charconst truncates wrongly for preprocessor
   30|       |#endif
   31|       |
   32|      1|int main() {
   33|      1|  if (LONG_CHARCONST != SHORT_CHARCONST){
   34|      0|    abort();
   35|      0|  }
   36|      1|  if (LONG_CHARCONST != SHORT_CHARCONST)
   37|      1|    abort();
   38|      1|  if (POS_CHARCONST < 0)
   39|      0|    abort();
   40|      1|  printf("passed\n");
   41|      1|  return 0;
   42|      1|}


In my opinion, line #34, #37 and #39 should not be 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/20210304/7669e931/attachment.html>


More information about the llvm-bugs mailing list