Issue |
149772
|
Summary |
[LLVM-COV] Macro statements cause incorrect coverage for switch-case statements
|
Labels |
new issue
|
Assignees |
|
Reporter |
8ss-boop
|
llvm version:
clang version 21.0.0git (https://github.com/llvm/llvm-project.git 872eac7af0050813062baba9662beb81093b6b55)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /root/software/llvm-releases/llvm-0704/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
```c
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define SW(n, c) case n: return (int)(c)
int get_value(char ch)
{
if (isalnum(ch))
switch (ch) {
SW('0', -1);
SW('1', 2);
SW('2', 3);
SW('3', 5);
SW('4', 7);
SW('5', 11);
SW('6', 13);
SW('7', 17);
SW('8', 19);
SW('9', 23);
SW('a', 29);
SW('A', 29);
}
return -1;
}
int main(void)
{
char input = '7';
int result = get_value(input);
printf("Value for '%c': %d\n", input, result);
return EXIT_SUCCESS;
}
```
for the program above, we got the following coverage report from llvm-cov
```
/*
clang -std=c2x -lm -fcoverage-mapping -fprofile-instr-generate test.c
./a.out
llvm-profdata merge default.profraw -o default.profdata;
llvm-cov show --show-line-counts -instr-profile="" ./a.out > test.c.lcov
*/
1| |#include <stdio.h>
2| |#include <ctype.h>
3| |#include <stdlib.h>
4| 1|#define SW(n, c) case n: return (int)(c)
5| |int get_value(char ch)
6| 1|{
7| 1| if (isalnum(ch))
8| 1| switch (ch) {
9| 0| SW('0', -1);
10| 0| SW('1', 2);
11| 0| SW('2', 3);
12| 0| SW('3', 5);
13| 0| SW('4', 7);
14| 0| SW('5', 11);
15| 0| SW('6', 13);
16| 1| SW('7', 17);
17| 0| SW('8', 19);
18| 0| SW('9', 23);
19| 0| SW('a', 29);
20| 1| SW('A', 29);
21| 1| }
22| 0| return -1;
23| 1|}
24| |int main(void)
25| 1|{
26| 1| char input = '7';
27| 1| int result = get_value(input);
28| 1| printf("Value for '%c': %d\n", input, result);
29| | return EXIT_SUCCESS;
30| 1|}
```
the output is:
```
Value for '7': 17
```
Obviously, only line16, which corresponding to input ‘7’, was executed. Line 20 was wrongly marked as executed.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs