https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128667

            Bug ID: 128667
           Summary: Debug marker between suppress_coverage regions changes
                    the gcov CFG checksum
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yqtian668 at gmail dot com
  Target Milestone: ---

GCC 17 changes the gcov CFG checksum when I compile the same C input with
-g versus -g0.  This happens with -fprofile-arcs and two separate
#pragma GCC suppress_coverage regions.  The ordinary instructions are the same.

Reproducer (source.c, no headers):

int g, h;
void f(int x)
{
  if (x) {
#pragma GCC suppress_coverage begin
  g = 1;
#pragma GCC suppress_coverage end
  ;
#pragma GCC suppress_coverage begin
  h = 2;
#pragma GCC suppress_coverage end
  }
  g++;
}

Compile both variants in the same directory, using the same output name so
that the gcov data path and compile stamp do not introduce unrelated
differences:

gcc -O2 -fprofile-arcs -frandom-seed=1 -g0 -S source.c -o w.s
cp w.s no-debug.s
gcc -O2 -fprofile-arcs -frandom-seed=1 -g -S source.c -o w.s
cp w.s with-debug.s

On x86_64-pc-linux-gnu with GCC 17.0.0 20261015 (experimental), revision
84348add236100e5f69a3e9ec4f7b1038bf2b83d, the cfg_checksum in the
__gcov_.f data is 357215991 with -g0 and 1152824444 with -g.  The object
checksum changes as well.  The
ordinary instructions for f are unchanged.  This can make coverage data
from one build incompatible with the notes from the other build.

The first differing compiler pass is cfg.  With -g, the empty statement
between the pragma regions has a DEBUG BEGIN_STMT marker whose location is
outside both regions.  In make_blocks_1 (gcc/tree-cfg.cc), the call to
in_pragma_suppress_coverage_p also processes this debug marker.  It changes
the suppression state and starts additional basic blocks.  The -g CFG has
two more blocks by the time branch_prob calculates the checksum.  A local
causal change that updates the suppression state only for non-debug
statements removes the checksum difference and leaves the -g0 assembly
unchanged.  This is not yet a submitted patch.

This is related to PR gcov-profile/128346
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128346), which fixed a
different debug-marker interaction in gimple_can_merge_blocks_p.  I also
reproduced the present case with a local build based on GCC master
cf6e20578 (2026-11-01) plus the PR128346 fix, so that fix does not cover
this case.  At master revision a1fc780b5 (2026-11-12), the same
make_blocks_1 call still processes debug
statements; I have not built that exact revision.

Expected: debug markers should not change the coverage CFG checksum for
this source and compilation options.

Reply via email to