Wcoverage-mismatch is meant to "Warn in case profiles in -fprofile-use do not
match"
Currently, gcc compiler warns about the following two cases of source code
changes which alert the programmer to re-generate the profiles :
1. Control flow mismatch
If functions' control flow has been altered after profile generation, the
profile count data will not be able to match the cfg_checksum.
Hence the warning, "warning: the control flow of function 'XXX' does not
match its profile data (counter 'YYY') [-Werror=coverage-mismatch]"
2. Function is physically moved to a different location
If existing functions are physically swapped in the source file, gcc alerts
the user about potentially stale profiles for all the affected functions.
Hence the warning, "warning : source locations for function 'XXX' have
changed, the profile data may be out of date [-Werror=coverage-mismatch]"
So, if new function foo() is added in the source file before existing
functions, gcc alerts the user about potentially stale profiles of the
already seen functions.
Note however, there is no warning about the new function foo(). Hence, my
proposal #3 below which will cover foo() in this scenario.
Proposing to add the following cases which are not currently covered :
3. If a new function foo() is added to the file. Proposal to add a warning along
the lines of -
"warning : profile for function ‘XXX’ not found in profile data
[-Wcoverage-mismatch]"
The corner case of foo() being added to the end of the file is exclusively
covered by #3.
4. A new source file is added to the project after profile generation phase.
Proposal to add a warning per function along the lines of -
"warning : profile count data file not found, regenerating profiles may help
[-Wcoverage-mismatch]"
For both #3 and #4, gcc currently does not warn. Although, one can infer that
the count profile data for a specific function / file are missing from the dump
files, adding warnings #3 and #4 makes the coverage-mismatch set of warnings
more complete for a better end user experience.