In many cases, these code regions are just redundant, but sometimes they could be assigned to the counter of the parent code region instead of the counter of the nested block.
Details
- Reviewers
davidxl bogner vsk - Commits
- rGfc05ee344cce: [Coverage] Suppress creating a code region if the same area is covered by an…
rC280199: [Coverage] Suppress creating a code region if the same area is covered by an…
rL280199: [Coverage] Suppress creating a code region if the same area is covered by an…
Diff Detail
Event Timeline
This patch fixes the following issue:
$ cat > test.cpp << EOF void dummy() {} #define MACRO_1 dummy() #define MACRO_2 MACRO_1 int main() { int i = 0; if (i > 5) MACRO_2; } EOF $ clang++ -fprofile-instr-generate -fcoverage-mapping dummy.cpp test.cpp $ ./a.out $ llvm-profdata merge -o default.profdata default.profraw $ llvm-cov show a.out -instr-profile --show-expansions default.profdata 1| 0|void dummy() {} 2| | 3| 0|#define MACRO_1 dummy() 4| | 5| 1|#define MACRO_2 MACRO_1 6| | 7| 1|int main() { 8| 1| int i = 0; 9| 1| if (i > 5) 10| 1| MACRO_2; ------------------ | | 5| 1|#define MACRO_2 MACRO_1 | | ------------------ | | | | 3| 0|#define MACRO_1 dummy() | | ------------------ ------------------ 11| 1|}
The result of the fixed version:
1| 0|void dummy() {} 2| | 3| 0|#define MACRO_1 dummy() 4| | 5| 0|#define MACRO_2 MACRO_1 6| | 7| 1|int main() { 8| 1| int i = 0; 9| 1| if (i > 5) 10| 0| MACRO_2; ------------------ | | 5| 0|#define MACRO_2 MACRO_1 | | ------------------ | | | | 3| 0|#define MACRO_1 dummy() | | ------------------ ------------------ 11| 1|}
Thanks for looking into this! I like the SourceRegionFilter setup.
lib/CodeGen/CoverageMappingGen.cpp | ||
---|---|---|
261 | Nit, is the default value needed? | |
634 | Out of curiosity, is this stable_sort step required for correctness? Or would our CHECK lines break without this? In either case, would it be feasible to merge this step with the stable_sort in CoverageMappingWriter::write()? |
- Removed a default value in emitSourceRegions(), added the corresponding argument to its call in EmptyCoverageMappingBuilder::write().
- Removed an additional sorting step in CounterCoverageMappingBuilder::write(), the patch is now depends on the extended sorting creteria in CoverageMappingWriter::write(), see D24034.
Nit, is the default value needed?