cgccerlangcode-coveragecflags

What does the gcc warning "coverage_mismatch" mean?


Today I meet a Werror=Wcoverage_mismatch error when compiling some erlang/opt:

beam/beam_emu.c: In function 'erts_current_reductions':                                                     
beam/beam_emu.c:3150:1: error: the control flow of function 'erts_current_reductions' does not match its profile data (counter 'arcs') [-Werror=coverage-mismatch]             
 } 
...

But I don't know what does it mean and google tells me nothing about this flag. Below is gcc source code

if (entry->n_counts != n_counts)
      warning_printed = warning_at(
          DECL_SOURCE_LOCATION(current_function_decl), OPT_Wcoverage_mismatch,
          "number of counters in profile data for function %qD "
          "does not match "
          "its profile data (counter %qs, expected %i and have %i)",
          current_function_decl, ctr_names[counter], entry->n_counts, n_counts);
    else
      warning_printed = warning_at(
          DECL_SOURCE_LOCATION(current_function_decl), OPT_Wcoverage_mismatch,
          "the control flow of function %qD does not match "
          "its profile data (counter %qs)",
          current_function_decl, ctr_names[counter]);

Solution

  • See the GCC (9.2.0) manual on Warning options:

    -Wno-coverage-mismatch

    Warn if feedback profiles do not match when using the -fprofile-use option. If a source file is changed between compiling with -fprofile-generate and with -fprofile-use, the files with the profile feedback can fail to match the source file and GCC cannot use the profile feedback information. By default, this warning is enabled and is treated as an error. -Wno-coverage-mismatch can be used to disable the warning or -Wno-error=coverage-mismatch can be used to disable the error. Disabling the error for this warning can result in poorly optimized code and is useful only in the case of very minor changes such as bug fixes to an existing code-base. Completely disabling the warning is not recommended.

    So, it appears that your source code has changed since the time when it was compiled, and this is likely to cause problems (hence the error message). Recompile and rerun the profiling.