Fix gcov path counting with insert_with_suffix
Ensures correct path counts in gcov by using a more robust insertion method for prime paths in SCCs.
A bug in path instrumentation for gcov has been fixed by changing how prime paths are inserted into SCCs. The previous use of insert instead of insert_with_suffix could lead to non-maximal paths being preserved, resulting in incorrect path counts reported by gcov. Using insert_with_suffix ensures all path suffixes are correctly processed, even if it incurs a slight compile-time overhead.
In Details
The prime-paths.cc file handles the generation of Huffman-coding-based coverage data (.gcno files). The commit changes scc_exit_prime_paths to use insert_with_suffix instead of insert. This addresses a subtle bug where insert could terminate early if a path was a subpath of another, leading to an incomplete trie. This affected gcov's path counting, especially when combined with pruning of the last block before function exit, which resulted in gcov reporting fewer paths than scc_exit_prime_paths would have indicated.
- gcov
- A code coverage tool that analyzes program execution data to report on which lines of source code were executed. It works in conjunction with compiler flags to generate execution traces.
- prime paths
- In the context of control flow graphs, prime paths are a set of fundamental paths that can generate all possible execution paths through a program. They are used for efficient coverage analysis.
- SCC
- Strongly Connected Component. A subgraph within a larger directed graph where every vertex is reachable from every other vertex within that subgraph. In control flow graphs, SCCs often represent loops.
- Huffman coding
- A lossless data compression algorithm. In this context, it's used to compress coverage information (like path data) stored in
.gcnofiles. - trie
- A tree-like data structure used for efficient retrieval of keys in a dataset of strings. In this context, it's used to store and manage program paths for coverage analysis.