gcc 警告“coverage_mismatch”是什么意思?

陳 力*_*陳 力 5 c erlang gcc code-coverage cflags

今天我Werror=Wcoverage_mismatch在编译一些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]             
 } 
...
Run Code Online (Sandbox Code Playgroud)

但我不知道这是什么意思,谷歌也没有告诉我关于这个标志的任何信息。下面是gcc源代码

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]);
Run Code Online (Sandbox Code Playgroud)

Jon*_*ler 6

有关警告选项,请参阅 GCC (9.2.0) 手册:

-Wno-coverage-mismatch

使用该选项时,如果反馈配置文件不匹配,则会发出警告-fprofile-use-fprofile-generate如果在使用和 使用进行编译之间更改了源文件-fprofile-use,则具有配置文件反馈的文件可能无法与源文件匹配,并且 GCC 无法使用配置文件反馈信息。默认情况下,此警告处于启用状态并被视为错误。-Wno-coverage-mismatch可用于禁用警告或-Wno-error=coverage-mismatch可用于禁用错误。禁用此警告的错误可能会导致代码优化不佳,并且仅在非常小的更改(例如对现有代码库进行错误修复)的情况下才有用。不建议完全禁用警告。

因此,您的源代码自编译以来似乎已发生更改,这可能会导致问题(因此会出现错误消息)。重新编译并重新运行分析。