Skip to content

[LLVM-COV] Coverage errors caused by macro definitions #54579

Open
@zhangxy-97

Description

@zhangxy-97

The macro variable N is used in the If conditional statement, causing line 12 to be incorrectly marked as being executed once.

$ clang -v

clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.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.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9.3.0
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/10.2.0
Selected GCC installation: /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/10.2.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

Source code:

    1|      1|#define N 1
    2|      0|#define TRUE 1
    3|       |#include <stdlib.h>
    4|      0|#define ADD(a,b) a + b
    5|       |
    6|      0|void myExit() { exit(0); }
    7|       |
    8|       |int zero = 0;
    9|       |int tmp = 0;
   10|      1|int main() {
   11|      1|   if (zero > N) 
   12|      1|      return 0;
   13|      1|   else {
   14|      1|      exit(0);
   15|      1|   }
   16|      0|   if (zero > N) {
   17|      0|      myExit();
   18|      0|      tmp = TRUE;
   19|      0|   } else
   20|      0|      myExit();
   21|      0|   
   22|      0|   if (ADD(1, 2) != ADD(2, 1)) {
   23|      0|      ;
   24|      0|   }
   25|      0|}

In addition, the termination instruction should only be executed once in the main function, and line 12 should be marked as unexecuted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions