[PATCH] D18831: [Coverage] Use the count value of the outer region for an expansion region.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 03:14:05 PDT 2016
ikudrin added a comment.
The motivation case for this patch is the following:
$ cat > sample.cpp << EOF
#define DO_LOOP1() \
for (int K = 0; K < 2; ++K) {}
#define DO_LOOP2() \
for (int K = 0; K < 2; ++K) {}
#define JUST_EXPAND() DO_LOOP2()
int main() {
DO_LOOP1();
JUST_EXPAND();
return 0;
}
EOF
$ clang++ -fprofile-instr-generate -fcoverage-mapping sample.cpp
$ ./a.out
$ llvm-profdata merge -o default.profdata default.profraw
$ llvm-cov show a.out -instr-profile default.profdata
| 1|#define DO_LOOP1() \
3| 2| for (int K = 0; K < 2; ++K) {}
| 3|
| 4|#define DO_LOOP2() \
3| 5| for (int K = 0; K < 2; ++K) {}
| 6|
3| 7|#define JUST_EXPAND() DO_LOOP2()
| 8|
1| 9|int main() {
3| 10| DO_LOOP1();
1| 11| JUST_EXPAND();
1| 12| return 0;
1| 13|}
As you may see, the counts for `DO_LOOP` macroses are 3, and these values are propagated to the outer code. As a result, counts for lines 7 and 10 are shown as `3` which looks quite weird.
After applying the patch, the output of llvm-cov looks more predictable:
$ llvm-cov show a.out -instr-profile default.profdata
| 1|#define DO_LOOP1() \
3| 2| for (int K = 0; K < 2; ++K) {}
| 3|
| 4|#define DO_LOOP2() \
3| 5| for (int K = 0; K < 2; ++K) {}
| 6|
1| 7|#define JUST_EXPAND() DO_LOOP2()
| 8|
1| 9|int main() {
1| 10| DO_LOOP1();
1| 11| JUST_EXPAND();
1| 12| return 0;
1| 13|}
http://reviews.llvm.org/D18831
More information about the llvm-commits
mailing list