https://gcc.gnu.org/g:b27f5e3c5d98d7c740c8f00aaeab9f1dea48c683
commit r17-5784-gb27f5e3c5d98d7c740c8f00aaeab9f1dea48c683 Author: Yongqiang Tian <[email protected]> Date: Sun Nov 1 09:09:05 2026 -0700 [PATCH] tree-cfg: Ignore debug stmts when checking coverage nops [PR128346] gimple_can_merge_blocks_p checks the final statement of a block for the compiler-inserted nop that marks a coverage-suppression boundary. A trailing DEBUG_BEGIN_STMT hides that nop under -g, allows the blocks to be merged, and changes the gcov CFG checksum even though the generated code is unchanged. Use gsi_last_nondebug_bb so debug markers do not affect the merge decision. Add a focused regression test. The test case was found by a non-AI automated testing tool. Assisted-by: OpenAI Codex 5.6 Sol. Bootstrapped and regression tested on x86_64-pc-linux-gnu. The focused test fails before the change and passes after it. PR gcov-profile/128346 gcc/ChangeLog: * tree-cfg.cc (gimple_can_merge_blocks_p): Ignore debug statements when examining the end of a block. gcc/testsuite/ChangeLog: * gcc.misc-tests/gcov-45.c: New test. Signed-off-by: Yongqiang Tian <[email protected]> Diff: --- gcc/testsuite/gcc.misc-tests/gcov-45.c | 19 +++++++++++++++++++ gcc/tree-cfg.cc | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.misc-tests/gcov-45.c b/gcc/testsuite/gcc.misc-tests/gcov-45.c new file mode 100644 index 000000000000..c7b2230485e1 --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-45.c @@ -0,0 +1,19 @@ +/* PR gcov-profile/128346 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -g -fno-thread-jumps -fprofile-arcs -fdump-tree-cfg-details" } */ + +int bar (int); + +#pragma GCC suppress_coverage begin +int +foo (int a) +{ + a; +#pragma GCC suppress_coverage end + if (a > 3) + a = bar (a); + return bar (a); +} + +/* A debug marker must not hide the coverage-suppression nop. */ +/* { dg-final { scan-tree-dump-not "Merging blocks 2 and 3" "cfg" } } */ diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index ba1d4a125adc..93a830f0eb84 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -1874,7 +1874,7 @@ gimple_can_merge_blocks_p (basic_block a, basic_block b) /* If A ends by a statement causing exceptions or something similar, we cannot merge the blocks. */ - stmt = *gsi_last_bb (a); + stmt = *gsi_last_nondebug_bb (a); if (stmt && stmt_ends_bb_p (stmt)) return false;
