Gcov coverage checks ignore debug statements
Ensures Gcov CFG checksums are not affected by debug statements near coverage nops.
This commit modifies the gimple_can_merge_blocks_p function to ignore debug statements when checking for compiler-inserted nops that mark coverage-suppression boundaries. Previously, a trailing DEBUG_BEGIN_STMT could hide these nops when debugging (-g) was enabled, incorrectly allowing blocks to merge. This change prevents debug markers from altering the Gcov Control Flow Graph (CFG) checksum, ensuring it accurately reflects the generated code even with debugging information.
In Details
The gimple_can_merge_blocks_p function in tree-cfg.cc previously used gsi_last to examine the final statement of a block for coverage-related nops. When -g was enabled, a DEBUG_BEGIN_STMT could appear as the last statement, hiding the intended coverage nop. This led to incorrect block merging and altered Gcov CFG checksums. By changing the check to use gsi_last_nondebug_bb, debug statements are now skipped, ensuring that the presence of debug information does not affect block merging decisions or the CFG checksum.
- Gcov
- A code coverage utility that analyzes program execution data to determine which lines of code were executed.
- CFG
- Control Flow Graph, a representation of a program's execution paths. In Gcov, it's used to track coverage information.
- nop
- No Operation. An instruction that does nothing. In this context, it's a compiler-inserted nop used as a marker.
- gimple_can_merge_blocks_p
- A GCC internal function that determines if two basic blocks can be merged without affecting program semantics or profiling information.
- DEBUG_BEGIN_STMT
- A special GIMPLE statement used internally by GCC to mark the beginning of a source code statement when debugging information is generated.
- checksum
- A value computed from a block of data for error detection. In Gcov, the CFG checksum helps ensure the integrity of the coverage data.