diff mbox series

PR86957

Message ID d1c04a22-7ed4-f598-2475-5859f9aafefa@oracle.com
State New
Headers show
Series PR86957 | expand

Commit Message

Indu Bhagat Sept. 5, 2018, 7:28 p.m. UTC
Patch for PR 86957 " gcc should warn about missing profiles for a compilation unit or a new function with -fprofile-use".
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86957

The patch adds -Wmissing-profile warning flag to alert user about cases when there is no profile data for a compilation unit or a function when using -fprofile-use.

The flag is on by default when -fprofile-use is specified and generates errors
by default (like -Wcoverage-mismatch).

The attachment pr86957-missing-profile-diagnostic shows the behavior of GCC with the patch.

Thanks
Indu

------------------------------------------------------


gcc/ChangeLog:

2018-09-05  "Indu Bhagat"  <"indu.bhagat@oracle.com">

         * common.opt: New warning option -Wmissing-profile.
         * coverage.c (get_coverage_counts): Add warning for missing .gcda file.
         * doc/invoke.texi: Document -Wmissing-profile.
         * profile.c (get_exec_counts): Add warning for missing feedback
           profile for a function.
         * toplev.c (process_options): -Wmissing-profile warning as error.

[Testcase 1] Missing profile data file with -fprofile-use. The sort.c file contains two functions main() and stop()

gcc -c sort.c -fprofile-use -O1 -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/
sort.c: In function ‘main’:
sort.c:29:1: error: ‘/data2/user/gcc-temp/fdo/profdata//#data2#user#gcc-temp#fdo#sort.gcda’ profile count data file not found, regenerating profiles may help [-Werror=missing-profile]
29 | }
   | ^
sort.c:29:1: error: profile for function ‘main’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
sort.c: In function ‘stop’:
sort.c:29:1: error: profile for function ‘stop’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
cc1: some warnings being treated as errors
make: *** [sort.o] Error 1

[Testcase 2] bubble_sort.c has a non-empty function bubble_sort() for which profile data exists.
Now at profile-use phase, a user adds empty function before1() before an existing lone function bubble_sort() and empty function after1() after the lone existing function bubble_sort()

gcc -c bubble_sort.c -fprofile-use -O1 -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/
bubble_sort.c: In function ‘after1’:
bubble_sort.c:19:1: error: profile for function ‘after1’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
19 | void after1() { }
   | ^~~~
bubble_sort.c: In function ‘bubble_sort’:
bubble_sort.c:19:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
bubble_sort.c: In function ‘before1’:
bubble_sort.c:19:1: error: profile for function ‘before1’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
cc1: some warnings being treated as errors
make: *** [bubble_sort.o] Error 1

[Testcase 3] Use -Wno-error=missing-profile to treat them as warnings, not errors

gcc -c bubble_sort.c -fprofile-use -O1 -Wno-error=missing-profile -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/
bubble_sort.c: In function ‘after1’:
bubble_sort.c:19:1: warning: profile for function ‘after1’ not found in profile data, regenerating profiles may help [-Wmissing-profile]
19 | void after1() { }
   | ^~~~
bubble_sort.c: In function ‘bubble_sort’:
bubble_sort.c:19:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
bubble_sort.c: In function ‘before1’:
bubble_sort.c:19:1: warning: profile for function ‘before1’ not found in profile data, regenerating profiles may help [-Wmissing-profile]
cc1: some warnings being treated as errors
make: *** [bubble_sort.o] Error 1

Comments

Martin Liška Sept. 11, 2018, 9:21 a.m. UTC | #1
On 09/05/2018 09:28 PM, Indu Bhagat wrote:

Hi.

Thanks for working on that. I believe it's useful enhancement. Note that I'm not profile feedback maintainer,
but I'll provide some feedback:

> Patch for PR 86957 " gcc should warn about missing profiles for a compilation unit or a new function with -fprofile-use".
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86957
> 
> The patch adds -Wmissing-profile warning flag to alert user about cases when there is no profile data for a compilation unit or a function when using -fprofile-use.
> 
> The flag is on by default when -fprofile-use is specified and generates errors
> by default (like -Wcoverage-mismatch).
> 
> The attachment pr86957-missing-profile-diagnostic shows the behavior of GCC with the patch.
> 
> Thanks
> Indu
> 
> ------------------------------------------------------
> 
> 
> gcc/ChangeLog:
> 
> 2018-09-05  "Indu Bhagat"  <"indu.bhagat@oracle.com">
> 
>         * common.opt: New warning option -Wmissing-profile.
>         * coverage.c (get_coverage_counts): Add warning for missing .gcda file.
>         * doc/invoke.texi: Document -Wmissing-profile.
>         * profile.c (get_exec_counts): Add warning for missing feedback
>           profile for a function.
>         * toplev.c (process_options): -Wmissing-profile warning as error.
> 
> 
> pr86957-patch
> 
> 
> diff --git a/gcc/common.opt b/gcc/common.opt
> index ebc3ef4..d93ddca 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -811,6 +811,10 @@ Wcoverage-mismatch
>  Common Var(warn_coverage_mismatch) Init(1) Warning
>  Warn in case profiles in -fprofile-use do not match.
>  
> +Wmissing-profile
> +Common Var(warn_missing_profile) Init(1) Warning
> +Warn in case profiles in -fprofile-use do not exist.

Maybe 'Want about missing profile for a function in -fprofile-use build.' ?

> +
>  Wvector-operation-performance
>  Common Var(warn_vector_operation_performance) Warning
>  Warn when a vector operation is compiled outside the SIMD.
> diff --git a/gcc/coverage.c b/gcc/coverage.c
> index bae6f5c..df031df 100644
> --- a/gcc/coverage.c
> +++ b/gcc/coverage.c
> @@ -341,16 +341,24 @@ get_coverage_counts (unsigned counter, unsigned expected,
>      {
>        static int warned = 0;
>  
> -      if (!warned++ && dump_enabled_p ())
> +      if (!warned++)
>  	{
> -	  dump_user_location_t loc
> -	    = dump_user_location_t::from_location_t (input_location);
> -	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
> +	  warning (OPT_Wmissing_profile,
> +		   "%qs profile count data file not found,"
> +		   " regenerating profiles may help",

I would not append 'regenerating profiles may help'. We don't do it for other
profile corruption warnings/errors.

> +		   da_file_name);
> +	  if (dump_enabled_p ())
> +	    {
> +	      dump_user_location_t loc
> +		= dump_user_location_t::from_location_t (input_location);
> +	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
> +			       "file %s not found\n",
> +			       da_file_name);
> +	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
>  			   (flag_guess_branch_prob
> -			    ? "file %s not found, execution counts estimated\n"
> -			    : "file %s not found, execution counts assumed to "
> -			    "be zero\n"),
> -			   da_file_name);
> +			    ? "execution counts estimated\n"
> +			    : "execution counts assumed to be zero\n"));
> +	    }
>  	}
>        return NULL;
>      }
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index ca92028..e62bcae 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -314,7 +314,7 @@ Objective-C and Objective-C++ Dialects}.
>  -Wlogical-op  -Wlogical-not-parentheses  -Wlong-long @gol
>  -Wmain  -Wmaybe-uninitialized  -Wmemset-elt-size  -Wmemset-transposed-args @gol
>  -Wmisleading-indentation  -Wmissing-attributes -Wmissing-braces @gol
> --Wmissing-field-initializers  -Wmissing-include-dirs @gol
> +-Wmissing-field-initializers  -Wmissing-include-dirs  -Wmissing-profile @gol
>  -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare @gol
>  -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
>  -Wnull-dereference  -Wodr  -Wno-overflow  -Wopenmp-simd  @gol
> @@ -4816,6 +4816,25 @@ This warning is enabled by @option{-Wall}.
>  @opindex Wno-missing-include-dirs
>  Warn if a user-supplied include directory does not exist.
>  
> +@item -Wmissing-profile
> +@opindex Wmissing-profile
> +@opindex Wno-missing-profile
> +Warn if feedback profiles are missing when using the
> +@option{-fprofile-use} option.
> +If a new function or a new file is added to the user code between compiling
> +with @option{-fprofile-gen} and with @option{-fprofile-use} without

s/profile-gen/profile-generate

> +regenerating the profiles, the profile feedback data files do not contain any
> +profile feedback information for the newly
> +added function or file respectively. 

I would suggest to split the sentence.

 Also, in the case when profile count data
> +(.gcda) files are wiped out, GCC cannot use any profile feedback
> +information.  In all these cases, warnings are issued to inform the user that a
> +profile generation step is due.  By default, this warning is enabled and is
> +treated as an error.  @option{-Wno-missing-profile} can be used to disable the
> +warning or @option{-Wno-error=missing-profile} 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 cases when non-existent profile data is
> +justified.  Completely disabling the warning is not recommended.
> +
>  @item -Wmultistatement-macros
>  @opindex Wmultistatement-macros
>  @opindex Wno-multistatement-macros
> @@ -9899,8 +9918,10 @@ Before you can use this option, you must first generate profiling information.
>  
>  By default, GCC emits an error message if the feedback profiles do not
>  match the source code.  This error can be turned into a warning by using
> -@option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
> -code.
> +@option{-Wno-error=coverage-mismatch}.  Note this may result in poorly
> +optimized code.  Additionally, by default, GCC also emits an error message if
> +the feedback profiles do not exist.  The latter error can be turned into a
> +warning by using @option{-Wno-error=missing-profile}.
>  
>  If @var{path} is specified, GCC looks at the @var{path} to find
>  the profile feedback data files. See @option{-fprofile-dir}.
> diff --git a/gcc/profile.c b/gcc/profile.c
> index cb51e0d..40f9763 100644
> --- a/gcc/profile.c
> +++ b/gcc/profile.c
> @@ -286,7 +286,13 @@ get_exec_counts (unsigned cfg_checksum, unsigned lineno_checksum)
>    counts = get_coverage_counts (GCOV_COUNTER_ARCS, num_edges, cfg_checksum,
>  				lineno_checksum, &profile_info);
>    if (!counts)
> -    return NULL;
> +    {
> +      warning (OPT_Wmissing_profile,
> +	       "profile for function %qE not found in profile data,"
> +	       " regenerating profiles may help",
> +	       DECL_ASSEMBLER_NAME (current_function_decl));
> +      return NULL;
> +    }

I hope we can do better here:

      warning_at (DECL_SOURCE_LOCATION (current_function_decl),
		  OPT_Wmissing_profile,
		  "profile for function %qD not found in profile data",
		  current_function_decl);

Then you'll see better location:

main.c:19:5: warning: profile for function ‘main’ not found in profile data [-Wmissing-profile]
19 | int main(int argc, char **argv)
   |     ^~~~

I'm wondering whether we want to report missing profiles for functions that live
in a file for which we reported missing .gcda file?

main.c: In function ‘main’:
main.c:22:1: warning: ‘/tmp/main.gcda’ profile count data file not found, regenerating profiles may help [-Wmissing-profile]
22 | }
   | ^
main.c:19:5: warning: profile for function ‘main’ not found in profile data [-Wmissing-profile]
19 | int main(int argc, char **argv)
   |     ^~~~
main.c: In function ‘bar’:
main.c:14:1: warning: profile for function ‘bar’ not found in profile data [-Wmissing-profile]
14 | bar()
   | ^~~
main.c: In function ‘foo’:
main.c:7:1: warning: profile for function ‘foo’ not found in profile data [-Wmissing-profile]
7 | foo()
  | ^~~

I would limit that just to the first warning. Otherwise one can end up with a wall of text.

>  
>    get_working_sets ();
>  
> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index 9fb83d4..5891554 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1782,14 +1782,24 @@ process_options (void)
>        || !targetm.have_prologue () || !targetm.have_epilogue ())
>      flag_ipa_ra = 0;
>  
> -  /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
> -     have not been set.  */
> -  if (!global_options_set.x_warnings_are_errors
> -      && warn_coverage_mismatch
> -      && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
> -          DK_UNSPECIFIED))
> -    diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
> -                                    DK_ERROR, UNKNOWN_LOCATION);
> +  if (!global_options_set.x_warnings_are_errors)
> +    {
> +      /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
> +	 have not been set.  */
> +      if (warn_coverage_mismatch
> +	  && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
> +	      DK_UNSPECIFIED))
> +	diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
> +					DK_ERROR, UNKNOWN_LOCATION);
> +
> +      /* Enable -Werror=missing-profile when -Werror and -Wno-error
> +	 have not been set.  */
> +      if (warn_missing_profile
> +	  && (global_dc->classify_diagnostic[OPT_Wmissing_profile] ==
> +	      DK_UNSPECIFIED))
> +	diagnostic_classify_diagnostic (global_dc, OPT_Wmissing_profile,
> +					DK_ERROR, UNKNOWN_LOCATION);
> +    }

I would prefer not to enable error of the option. Mainly due to configure
scripts that have missing profiles (example from postgres):

configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/home/marxin/Programming/postgres':
configure: error: C compiler cannot create executables
See `config.log' for more details

configure:3942: gcc -O2 -fprofile-use -g  -O2 -fprofile-use -g conftest.c  >&5
conftest.c: In function 'main':
conftest.c:23:1: error: '/home/marxin/Programming/postgres/conftest.gcda' profile count data file not found, regenerating profiles may help [-Werror=missing-profile]
23 | }
   | ^
conftest.c:23:1: error: profile for function 'main' not found in profile data, regenerating profiles may help [-Werror=missing-profile]

Anyway, thanks for working on that.

Martin

>  
>    /* Save the current optimization options.  */
>    optimization_default_node = build_optimization_node (&global_options);
> 
> 
> pr86957-missing-profile-diagnostic
> 
> 
> [Testcase 1] Missing profile data file with -fprofile-use. The sort.c file contains two functions main() and stop()
> 
> gcc -c sort.c -fprofile-use -O1 -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/
> sort.c: In function ‘main’:
> sort.c:29:1: error: ‘/data2/user/gcc-temp/fdo/profdata//#data2#user#gcc-temp#fdo#sort.gcda’ profile count data file not found, regenerating profiles may help [-Werror=missing-profile]
> 29 | }
>    | ^
> sort.c:29:1: error: profile for function ‘main’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
> sort.c: In function ‘stop’:
> sort.c:29:1: error: profile for function ‘stop’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
> cc1: some warnings being treated as errors
> make: *** [sort.o] Error 1
> 
> [Testcase 2] bubble_sort.c has a non-empty function bubble_sort() for which profile data exists.
> Now at profile-use phase, a user adds empty function before1() before an existing lone function bubble_sort() and empty function after1() after the lone existing function bubble_sort()
> 
> gcc -c bubble_sort.c -fprofile-use -O1 -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/
> bubble_sort.c: In function ‘after1’:
> bubble_sort.c:19:1: error: profile for function ‘after1’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
> 19 | void after1() { }
>    | ^~~~
> bubble_sort.c: In function ‘bubble_sort’:
> bubble_sort.c:19:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
> bubble_sort.c: In function ‘before1’:
> bubble_sort.c:19:1: error: profile for function ‘before1’ not found in profile data, regenerating profiles may help [-Werror=missing-profile]
> cc1: some warnings being treated as errors
> make: *** [bubble_sort.o] Error 1
> 
> [Testcase 3] Use -Wno-error=missing-profile to treat them as warnings, not errors
> 
> gcc -c bubble_sort.c -fprofile-use -O1 -Wno-error=missing-profile -fprofile-dir=/data2/user/gcc-temp/fdo/profdata/
> bubble_sort.c: In function ‘after1’:
> bubble_sort.c:19:1: warning: profile for function ‘after1’ not found in profile data, regenerating profiles may help [-Wmissing-profile]
> 19 | void after1() { }
>    | ^~~~
> bubble_sort.c: In function ‘bubble_sort’:
> bubble_sort.c:19:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
> bubble_sort.c: In function ‘before1’:
> bubble_sort.c:19:1: warning: profile for function ‘before1’ not found in profile data, regenerating profiles may help [-Wmissing-profile]
> cc1: some warnings being treated as errors
> make: *** [bubble_sort.o] Error 1 
>
Martin Liška Sept. 11, 2018, 9:23 a.m. UTC | #2
On 09/05/2018 09:28 PM, Indu Bhagat wrote:
> Patch for PR 86957 " gcc should warn about missing profiles for a compilation unit or a new function with -fprofile-use".
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86957
> 
> The patch adds -Wmissing-profile warning flag to alert user about cases when there is no profile data for a compilation unit or a function when using -fprofile-use.
> 
> The flag is on by default when -fprofile-use is specified and generates errors
> by default (like -Wcoverage-mismatch).
> 
> The attachment pr86957-missing-profile-diagnostic shows the behavior of GCC with the patch.
> 
> Thanks
> Indu
> 
> ------------------------------------------------------
> 
> 
> gcc/ChangeLog:
> 
> 2018-09-05  "Indu Bhagat"  <"indu.bhagat@oracle.com">
> 
>         * common.opt: New warning option -Wmissing-profile.
>         * coverage.c (get_coverage_counts): Add warning for missing .gcda file.
>         * doc/invoke.texi: Document -Wmissing-profile.
>         * profile.c (get_exec_counts): Add warning for missing feedback
>           profile for a function.
>         * toplev.c (process_options): -Wmissing-profile warning as error.
> 

... and please add a test-case for the missing file. That's easy to achieve by running
a test-case with -fprofile-use.

Martin
Indu Bhagat Sept. 15, 2018, 11:28 p.m. UTC | #3
Thanks for the reviews. I have incorporated all but one (See below; its the change in the warning's
brief summary in common.opt) in the patch.

In this patch,

1. -Wmissing-profile is a warning by default and is ON by default with
    -fprofile-use
2. Attached pr86957-missing-profile-diagnostic-2 shows the warning messages
3. Added a testcase for warning in the case of missing profile feedback data
    file for a compilation unit

Thanks

gcc/ChangeLog:

2018-09-14  "Indu Bhagat"<indu.bhagat@oracle.com>

         * common.opt: New warning option -Wmissing-profile.
         * coverage.c (get_coverage_counts): Add warning for missing .gcda file.
         * doc/invoke.texi: Document -Wmissing-profile.

gcc/testsuite/ChangeLog:

2018-09-14  "Indu Bhagat"<indu.bhagat@oracle.com>

         * gcc.dg/Wmissing-profile.c: New test.


On 09/11/2018 02:21 AM, Martin Liška wrote:
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index ebc3ef4..d93ddca 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -811,6 +811,10 @@ Wcoverage-mismatch
>>   Common Var(warn_coverage_mismatch) Init(1) Warning
>>   Warn in case profiles in -fprofile-use do not match.
>>   
>> +Wmissing-profile
>> +Common Var(warn_missing_profile) Init(1) Warning
>> +Warn in case profiles in -fprofile-use do not exist.
> Maybe 'Want about missing profile for a function in -fprofile-use build.' ?
>

Since, Wmissing-profile also warns when feedback data file is missing for a compilation unit, the
suggested text above will be more restrictive. So I did not change.
[Testcase 1] Missing profile data file with -fprofile-use. The sort.c file contains two functions main() and stop()

gcc -c sort.c -fprofile-use -O1 -fprofile-dir=/scratch/user/gcc-temp/fdo/profdata/
sort.c: In function ‘main’:
sort.c:29:1: warning: ‘/scratch/user/gcc-temp/fdo/profdata//#scratch#user#gcc-temp#fdo#sort.gcda’ profile count data file not found [-Wmissing-profile]
29 | }
   | ^


[Testcase 2] bubble_sort.c has a non-empty function bubble_sort() for which profile data exists.
Now at profile-use phase, a user adds empty function before1() before an existing lone function bubble_sort() and empty function after1() after the lone existing function bubble_sort()

gcc -c bubble_sort.c -fprofile-use -O1 -fprofile-dir=/scratch/user/gcc-temp/fdo/profdata/
bubble_sort.c:20:6: warning: profile for function ‘after1’ not found in profile data [-Wmissing-profile]
20 | void after1() { }
   |      ^~~~~~
bubble_sort.c: In function ‘bubble_sort’:
bubble_sort.c:20:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
20 | void after1() { }
   | ^~~~
bubble_sort.c: In function ‘before1’:
bubble_sort.c:3:6: warning: profile for function ‘before1’ not found in profile data [-Wmissing-profile]
3 | void before1() { }
  |      ^~~~~~~
cc1: some warnings being treated as errors
make: *** [bubble_sort.o] Error 1


[Testcase 3] Use -Wno-missing-profile to disable warnings (A coverage-mismatch error remains here because of source file changes as mentioned in Testcase 2 above; but no warnings are issued for before1() and after1())

gcc -c bubble_sort.c -fprofile-use -O1 -Wno-missing-profile -fprofile-dir=/scratch/user/gcc-temp/fdo/profdata/
bubble_sort.c: In function ‘bubble_sort’:
bubble_sort.c:20:1: error: source locations for function ‘bubble_sort’ have changed, the profile data may be out of date [-Werror=coverage-mismatch]
20 | void after1() { }
   | ^~~~
cc1: some warnings being treated as errors
diff --git a/gcc/common.opt b/gcc/common.opt
index ef6a630..53aac19 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -811,6 +811,10 @@ Wcoverage-mismatch
 Common Var(warn_coverage_mismatch) Init(1) Warning
 Warn in case profiles in -fprofile-use do not match.
 
+Wmissing-profile
+Common Var(warn_missing_profile) Init(1) Warning
+Warn in case profiles in -fprofile-use do not exist.
+
 Wvector-operation-performance
 Common Var(warn_vector_operation_performance) Warning
 Warn when a vector operation is compiled outside the SIMD.
diff --git a/gcc/coverage.c b/gcc/coverage.c
index bae6f5c..f9b54d8 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -341,16 +341,23 @@ get_coverage_counts (unsigned counter, unsigned expected,
     {
       static int warned = 0;
 
-      if (!warned++ && dump_enabled_p ())
+      if (!warned++)
 	{
-	  dump_user_location_t loc
-	    = dump_user_location_t::from_location_t (input_location);
-	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+	  warning (OPT_Wmissing_profile,
+		   "%qs profile count data file not found",
+		   da_file_name);
+	  if (dump_enabled_p ())
+	    {
+	      dump_user_location_t loc
+		= dump_user_location_t::from_location_t (input_location);
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+			       "file %s not found\n",
+			       da_file_name);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
 			   (flag_guess_branch_prob
-			    ? "file %s not found, execution counts estimated\n"
-			    : "file %s not found, execution counts assumed to "
-			    "be zero\n"),
-			   da_file_name);
+			    ? "execution counts estimated\n"
+			    : "execution counts assumed to be zero\n"));
+	    }
 	}
       return NULL;
     }
@@ -364,10 +371,17 @@ get_coverage_counts (unsigned counter, unsigned expected,
   elt.ctr = counter;
   entry = counts_hash->find (&elt);
   if (!entry || !entry->summary.num)
-    /* The function was not emitted, or is weak and not chosen in the
-       final executable.  Silently fail, because there's nothing we
-       can do about it.  */
-    return NULL;
+    {
+      if (summary)
+	warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+		    OPT_Wmissing_profile,
+		    "profile for function %qD not found in profile data",
+		    current_function_decl);
+      /* The function was not emitted, or is weak and not chosen in the
+	 final executable.  Silently fail, because there's nothing we
+	 can do about it.  */
+      return NULL;
+    }
   
   if (entry->cfg_checksum != cfg_checksum
       || entry->summary.num != expected)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ec12711..072327a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -314,7 +314,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wlogical-op  -Wlogical-not-parentheses  -Wlong-long @gol
 -Wmain  -Wmaybe-uninitialized  -Wmemset-elt-size  -Wmemset-transposed-args @gol
 -Wmisleading-indentation  -Wmissing-attributes -Wmissing-braces @gol
--Wmissing-field-initializers  -Wmissing-include-dirs @gol
+-Wmissing-field-initializers  -Wmissing-include-dirs  -Wmissing-profile @gol
 -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare @gol
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
 -Wnull-dereference  -Wodr  -Wno-overflow  -Wopenmp-simd  @gol
@@ -4211,8 +4211,8 @@ Warn about an invalid memory access that is found by Pointer Bounds Checker
 @opindex Wcoverage-mismatch
 Warn if feedback profiles do not match when using the
 @option{-fprofile-use} option.
-If a source file is changed between compiling with @option{-fprofile-gen} and
-with @option{-fprofile-use}, the files with the profile feedback can fail
+If a source file is changed between compiling with @option{-fprofile-generate}
+and with @option{-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.  @option{-Wno-coverage-mismatch} can be used to disable the
@@ -4816,6 +4816,23 @@ This warning is enabled by @option{-Wall}.
 @opindex Wno-missing-include-dirs
 Warn if a user-supplied include directory does not exist.
 
+@item -Wmissing-profile
+@opindex Wmissing-profile
+@opindex Wno-missing-profile
+Warn if feedback profiles are missing when using the
+@option{-fprofile-use} option.
+This option diagnoses those cases where a new function or a new file is added
+to the user code between compiling with @option{-fprofile-generate} and with
+@option{-fprofile-use}, without regenerating the profiles.  In these cases, the
+profile feedback data files do not contain any profile feedback information for
+the newly added function or file respectively.  Also, in the case when profile
+count data (.gcda) files are wiped out, GCC cannot use any profile feedback
+information.  In all these cases, warnings are issued to inform the user that a
+profile generation step is due.  @option{-Wno-missing-profile} can be used to
+disable the warning.  Ignoring the warning can result in poorly optimized code.
+Completely disabling the warning is not recommended and should be done only
+when non-existent profile data is justified.
+
 @item -Wmultistatement-macros
 @opindex Wmultistatement-macros
 @opindex Wno-multistatement-macros
@@ -9905,8 +9922,9 @@ Before you can use this option, you must first generate profiling information.
 
 By default, GCC emits an error message if the feedback profiles do not
 match the source code.  This error can be turned into a warning by using
-@option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
-code.
+@option{-Wno-error=coverage-mismatch}.  Note this may result in poorly
+optimized code.  Additionally, by default, GCC also emits a warning message if
+the feedback profiles do not exist (See @option{-Wmissing-profile}).
 
 If @var{path} is specified, GCC looks at the @var{path} to find
 the profile feedback data files. See @option{-fprofile-dir}.
diff --git a/gcc/testsuite/gcc.dg/Wmissing-profile.c b/gcc/testsuite/gcc.dg/Wmissing-profile.c
new file mode 100644
index 0000000..6ef1ac1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wmissing-profile.c
@@ -0,0 +1,5 @@
+/* PR gcov-profile/86957 */
+/* { dg-do compile } */
+/* { dg-options "-fprofile-use" } */
+
+void foo () { } /* { dg-warning "profile count data file not found" } */
Martin Liška Sept. 17, 2018, 10:10 a.m. UTC | #4
On 9/16/18 12:58 AM, Indu Bhagat wrote:
> Thanks for the reviews. I have incorporated them in this patch except the one 
> (changes in common.opt) below.
> 
> In this patch,
> 
> 1. -Wmissing-profile is a warning by default and is ON by default with 
>    -fprofile-use
> 2. Attached pr86957-missing-profile-diagnostic-2 shows the warning messages
> 3. Added a testcase for warning in the case of missing profile feedback data
>    file for a compilation unit
> 
> Thanks

Hi.

The patch looks fine for me now. Honza can you approve it?

Martin

> 
> gcc/ChangeLog:
> 
> 2018-09-14  "Indu Bhagat"  <"indu.bhagat@oracle.com">
> 
>         * common.opt: New warning option -Wmissing-profile.
>         * coverage.c (get_coverage_counts): Add warning for missing .gcda file.
>         * doc/invoke.texi: Document -Wmissing-profile.
> 
> gcc/testsuite/ChangeLog:
> 
> 2018-09-14  "Indu Bhagat"  <"indu.bhagat@oracle.com">
> 
>         * gcc.dg/Wmissing-profile.c: New test.
> 
> 
> On 09/11/2018 02:21 AM, Martin Liška wrote:
>>> --- a/gcc/common.opt
>>> +++ b/gcc/common.opt
>>> @@ -811,6 +811,10 @@ Wcoverage-mismatch
>>>  Common Var(warn_coverage_mismatch) Init(1) Warning
>>>  Warn in case profiles in -fprofile-use do not match.
>>>  
>>> +Wmissing-profile
>>> +Common Var(warn_missing_profile) Init(1) Warning
>>> +Warn in case profiles in -fprofile-use do not exist.
>> Maybe 'Want about missing profile for a function in -fprofile-use build.' ?
>>
> Since, it also warns when feedback file is missing for a compilation unit, the
> suggested text above will be more restrictive. So I did not change.
> 
>
Jan Hubicka Sept. 17, 2018, 10:52 a.m. UTC | #5
> On 9/16/18 12:58 AM, Indu Bhagat wrote:
> > Thanks for the reviews. I have incorporated them in this patch except the one 
> > (changes in common.opt) below.
> > 
> > In this patch,
> > 
> > 1. -Wmissing-profile is a warning by default and is ON by default with 
> >    -fprofile-use
> > 2. Attached pr86957-missing-profile-diagnostic-2 shows the warning messages
> > 3. Added a testcase for warning in the case of missing profile feedback data
> >    file for a compilation unit
> > 
> > Thanks
> 
> Hi.
> 
> The patch looks fine for me now. Honza can you approve it?
Patch looks OK.  We used to have this warning but it was removed by google floks
because if you build a static library it may happen that object file was never linked
into your test application, so its use is a bit limited. Having an option for this makes
sense to me though.

Honza
> 
> Martin
> 
> > 
> > gcc/ChangeLog:
> > 
> > 2018-09-14  "Indu Bhagat"  <"indu.bhagat@oracle.com">
> > 
> >         * common.opt: New warning option -Wmissing-profile.
> >         * coverage.c (get_coverage_counts): Add warning for missing .gcda file.
> >         * doc/invoke.texi: Document -Wmissing-profile.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 2018-09-14  "Indu Bhagat"  <"indu.bhagat@oracle.com">
> > 
> >         * gcc.dg/Wmissing-profile.c: New test.
> > 
> > 
> > On 09/11/2018 02:21 AM, Martin Liška wrote:
> >>> --- a/gcc/common.opt
> >>> +++ b/gcc/common.opt
> >>> @@ -811,6 +811,10 @@ Wcoverage-mismatch
> >>>  Common Var(warn_coverage_mismatch) Init(1) Warning
> >>>  Warn in case profiles in -fprofile-use do not match.
> >>>  
> >>> +Wmissing-profile
> >>> +Common Var(warn_missing_profile) Init(1) Warning
> >>> +Warn in case profiles in -fprofile-use do not exist.
> >> Maybe 'Want about missing profile for a function in -fprofile-use build.' ?
> >>
> > Since, it also warns when feedback file is missing for a compilation unit, the
> > suggested text above will be more restrictive. So I did not change.

Perhaps we want also to have reference from -fprofile-use documentation so users notice
this option.

Honza
> > 
> > 
>
Indu Bhagat Sept. 18, 2018, 7:24 p.m. UTC | #6
On 09/17/2018 03:52 AM, Jan Hubicka wrote:
>>> On 09/11/2018 02:21 AM, Martin Liška wrote:
>>>>> --- a/gcc/common.opt
>>>>> +++ b/gcc/common.opt
>>>>> @@ -811,6 +811,10 @@ Wcoverage-mismatch
>>>>>   Common Var(warn_coverage_mismatch) Init(1) Warning
>>>>>   Warn in case profiles in -fprofile-use do not match.
>>>>>   
>>>>> +Wmissing-profile
>>>>> +Common Var(warn_missing_profile) Init(1) Warning
>>>>> +Warn in case profiles in -fprofile-use do not exist.
>>>> Maybe 'Want about missing profile for a function in -fprofile-use build.' ?
>>>>
>>> Since, it also warns when feedback file is missing for a compilation unit, the
>>> suggested text above will be more restrictive. So I did not change.
> Perhaps we want also to have reference from -fprofile-use documentation so users notice
> this option.
>
> Honza
Thanks

Yes, I had added that in the patch. Following additional text will 
appear at the end of
-fprofile-use :

+ Additionally, by default, GCC also emits a warning message if
+the feedback profiles do not exist (See @option{-Wmissing-profile}).
Indu Bhagat Sept. 21, 2018, 11:27 p.m. UTC | #7
Attached is the refreshed patch for trunk.

After commit 264462 (Remove arc profile histogram in non-LTO mode.), the API
of get_coverage_counts was changed a bit. So the main difference between the
current version of my patch from the previous one is that :

Now I use
+      if (counter == GCOV_COUNTER_ARCS)
+       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+                   OPT_Wmissing_profile,
+                   "profile for function %qD not found in profile data",
+                   current_function_decl);

instead of
+      if (summary)
+       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+                   OPT_Wmissing_profile,
+                   "profile for function %qD not found in profile data",
+                   current_function_decl);

to warn about missing profile of a function only once (get_coverage_counts is
called from two diff flows : getting exec counts for arc counter and computing
histogram for other other counters)

I am not sure of any better way to avoid superfluous warnings per function.

Is the patch OK ?
diff --git a/gcc/common.opt b/gcc/common.opt
index ef6a630..53aac19 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -811,6 +811,10 @@ Wcoverage-mismatch
 Common Var(warn_coverage_mismatch) Init(1) Warning
 Warn in case profiles in -fprofile-use do not match.
 
+Wmissing-profile
+Common Var(warn_missing_profile) Init(1) Warning
+Warn in case profiles in -fprofile-use do not exist.
+
 Wvector-operation-performance
 Common Var(warn_vector_operation_performance) Warning
 Warn when a vector operation is compiled outside the SIMD.
diff --git a/gcc/coverage.c b/gcc/coverage.c
index 26cce2b..4b6df8a 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -304,16 +304,23 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
     {
       static int warned = 0;
 
-      if (!warned++ && dump_enabled_p ())
+      if (!warned++)
 	{
-	  dump_user_location_t loc
-	    = dump_user_location_t::from_location_t (input_location);
-	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+	  warning (OPT_Wmissing_profile,
+		   "%qs profile count data file not found",
+		   da_file_name);
+	  if (dump_enabled_p ())
+	    {
+	      dump_user_location_t loc
+		= dump_user_location_t::from_location_t (input_location);
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+			       "file %s not found\n",
+			       da_file_name);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
 			   (flag_guess_branch_prob
-			    ? "file %s not found, execution counts estimated\n"
-			    : "file %s not found, execution counts assumed to "
-			    "be zero\n"),
-			   da_file_name);
+			    ? "execution counts estimated\n"
+			    : "execution counts assumed to be zero\n"));
+	    }
 	}
       return NULL;
     }
@@ -327,10 +334,17 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
   elt.ctr = counter;
   entry = counts_hash->find (&elt);
   if (!entry)
-    /* The function was not emitted, or is weak and not chosen in the
-       final executable.  Silently fail, because there's nothing we
-       can do about it.  */
-    return NULL;
+    {
+      if (counter == GCOV_COUNTER_ARCS)
+	warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+		    OPT_Wmissing_profile,
+		    "profile for function %qD not found in profile data",
+		    current_function_decl);
+      /* The function was not emitted, or is weak and not chosen in the
+	 final executable.  Silently fail, because there's nothing we
+	 can do about it.  */
+      return NULL;
+    }
   
   if (entry->cfg_checksum != cfg_checksum)
     {
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index abbd9ec..ed56af3 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -315,7 +315,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wlogical-op  -Wlogical-not-parentheses  -Wlong-long @gol
 -Wmain  -Wmaybe-uninitialized  -Wmemset-elt-size  -Wmemset-transposed-args @gol
 -Wmisleading-indentation  -Wmissing-attributes -Wmissing-braces @gol
--Wmissing-field-initializers  -Wmissing-include-dirs @gol
+-Wmissing-field-initializers  -Wmissing-include-dirs  -Wmissing-profile @gol
 -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare @gol
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
 -Wnull-dereference  -Wodr  -Wno-overflow  -Wopenmp-simd  @gol
@@ -4218,8 +4218,8 @@ Warn about an invalid memory access that is found by Pointer Bounds Checker
 @opindex Wcoverage-mismatch
 Warn if feedback profiles do not match when using the
 @option{-fprofile-use} option.
-If a source file is changed between compiling with @option{-fprofile-gen} and
-with @option{-fprofile-use}, the files with the profile feedback can fail
+If a source file is changed between compiling with @option{-fprofile-generate}
+and with @option{-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.  @option{-Wno-coverage-mismatch} can be used to disable the
@@ -4823,6 +4823,23 @@ This warning is enabled by @option{-Wall}.
 @opindex Wno-missing-include-dirs
 Warn if a user-supplied include directory does not exist.
 
+@item -Wmissing-profile
+@opindex Wmissing-profile
+@opindex Wno-missing-profile
+Warn if feedback profiles are missing when using the
+@option{-fprofile-use} option.
+This option diagnoses those cases where a new function or a new file is added
+to the user code between compiling with @option{-fprofile-generate} and with
+@option{-fprofile-use}, without regenerating the profiles.  In these cases, the
+profile feedback data files do not contain any profile feedback information for
+the newly added function or file respectively.  Also, in the case when profile
+count data (.gcda) files are wiped out, GCC cannot use any profile feedback
+information.  In all these cases, warnings are issued to inform the user that a
+profile generation step is due.  @option{-Wno-missing-profile} can be used to
+disable the warning.  Ignoring the warning can result in poorly optimized code.
+Completely disabling the warning is not recommended and should be done only
+when non-existent profile data is justified.
+
 @item -Wmultistatement-macros
 @opindex Wmultistatement-macros
 @opindex Wno-multistatement-macros
@@ -9920,8 +9937,9 @@ Before you can use this option, you must first generate profiling information.
 
 By default, GCC emits an error message if the feedback profiles do not
 match the source code.  This error can be turned into a warning by using
-@option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
-code.
+@option{-Wno-error=coverage-mismatch}.  Note this may result in poorly
+optimized code.  Additionally, by default, GCC also emits a warning message if
+the feedback profiles do not exist (See @option{-Wmissing-profile}).
 
 If @var{path} is specified, GCC looks at the @var{path} to find
 the profile feedback data files. See @option{-fprofile-dir}.
diff --git a/gcc/testsuite/gcc.dg/Wmissing-profile.c b/gcc/testsuite/gcc.dg/Wmissing-profile.c
new file mode 100644
index 0000000..6ef1ac1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wmissing-profile.c
@@ -0,0 +1,5 @@
+/* PR gcov-profile/86957 */
+/* { dg-do compile } */
+/* { dg-options "-fprofile-use" } */
+
+void foo () { } /* { dg-warning "profile count data file not found" } */
Martin Sebor Sept. 24, 2018, 4:37 p.m. UTC | #8
On 09/21/2018 05:27 PM, Indu Bhagat wrote:
> Attached is the refreshed patch for trunk.
>
> After commit 264462 (Remove arc profile histogram in non-LTO mode.), the
> API
> of get_coverage_counts was changed a bit. So the main difference between
> the
> current version of my patch from the previous one is that :
>
> Now I use
> +      if (counter == GCOV_COUNTER_ARCS)
> +       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
> +                   OPT_Wmissing_profile,
> +                   "profile for function %qD not found in profile data",
> +                   current_function_decl);
>
> instead of
> +      if (summary)
> +       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
> +                   OPT_Wmissing_profile,
> +                   "profile for function %qD not found in profile data",
> +                   current_function_decl);
>
> to warn about missing profile of a function only once
> (get_coverage_counts is
> called from two diff flows : getting exec counts for arc counter and
> computing
> histogram for other other counters)
>
> I am not sure of any better way to avoid superfluous warnings per function.
>
> Is the patch OK ?
>

In the text below:

@@ -4823,6 +4823,23 @@
  This warning is enabled by @option{-Wall}.
  @opindex Wno-missing-include-dirs
  Warn if a user-supplied include directory does not exist.

+@item -Wmissing-profile
+@opindex Wmissing-profile
+@opindex Wno-missing-profile
+Warn if feedback profiles are missing when using the
+@option{-fprofile-use} option.
+This option diagnoses those cases where a new function or a new file is 
added
+to the user code between compiling with @option{-fprofile-generate} and 
with
+@option{-fprofile-use}, without regenerating the profiles.  In these 
cases, the
+profile feedback data files do not contain any profile feedback 
information for
+the newly added function or file respectively.  Also, in the case when 
profile
+count data (.gcda) files are wiped out, GCC cannot use any profile 
feedback
+information.

I would suggest to use the term "remove" or "delete" instead of
the informal "wipe out" when referring to removing files or their
contents.

Martin
Indu Bhagat Sept. 24, 2018, 7:21 p.m. UTC | #9
Done. Attached is updated patch.

Patch is tested on x86_64

Thanks


On 09/24/2018 09:37 AM, Martin Sebor wrote:
> I would suggest to use the term "remove" or "delete" instead of
> the informal "wipe out" when referring to removing files or their
> contents.
>
> Martin
diff --git a/gcc/common.opt b/gcc/common.opt
index ef6a630..53aac19 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -811,6 +811,10 @@ Wcoverage-mismatch
 Common Var(warn_coverage_mismatch) Init(1) Warning
 Warn in case profiles in -fprofile-use do not match.
 
+Wmissing-profile
+Common Var(warn_missing_profile) Init(1) Warning
+Warn in case profiles in -fprofile-use do not exist.
+
 Wvector-operation-performance
 Common Var(warn_vector_operation_performance) Warning
 Warn when a vector operation is compiled outside the SIMD.
diff --git a/gcc/coverage.c b/gcc/coverage.c
index 8f12778..19c696c 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -304,16 +304,23 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
     {
       static int warned = 0;
 
-      if (!warned++ && dump_enabled_p ())
+      if (!warned++)
 	{
-	  dump_user_location_t loc
-	    = dump_user_location_t::from_location_t (input_location);
-	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+	  warning (OPT_Wmissing_profile,
+		   "%qs profile count data file not found",
+		   da_file_name);
+	  if (dump_enabled_p ())
+	    {
+	      dump_user_location_t loc
+		= dump_user_location_t::from_location_t (input_location);
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+			       "file %s not found\n",
+			       da_file_name);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
 			   (flag_guess_branch_prob
-			    ? "file %s not found, execution counts estimated\n"
-			    : "file %s not found, execution counts assumed to "
-			    "be zero\n"),
-			   da_file_name);
+			    ? "execution counts estimated\n"
+			    : "execution counts assumed to be zero\n"));
+	    }
 	}
       return NULL;
     }
@@ -327,10 +334,17 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
   elt.ctr = counter;
   entry = counts_hash->find (&elt);
   if (!entry)
-    /* The function was not emitted, or is weak and not chosen in the
-       final executable.  Silently fail, because there's nothing we
-       can do about it.  */
-    return NULL;
+    {
+      if (counter == GCOV_COUNTER_ARCS)
+	warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+		    OPT_Wmissing_profile,
+		    "profile for function %qD not found in profile data",
+		    current_function_decl);
+      /* The function was not emitted, or is weak and not chosen in the
+	 final executable.  Silently fail, because there's nothing we
+	 can do about it.  */
+      return NULL;
+    }
   
   if (entry->cfg_checksum != cfg_checksum)
     {
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index abbd9ec..1b6cd68 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -315,7 +315,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wlogical-op  -Wlogical-not-parentheses  -Wlong-long @gol
 -Wmain  -Wmaybe-uninitialized  -Wmemset-elt-size  -Wmemset-transposed-args @gol
 -Wmisleading-indentation  -Wmissing-attributes -Wmissing-braces @gol
--Wmissing-field-initializers  -Wmissing-include-dirs @gol
+-Wmissing-field-initializers  -Wmissing-include-dirs  -Wmissing-profile @gol
 -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare @gol
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
 -Wnull-dereference  -Wodr  -Wno-overflow  -Wopenmp-simd  @gol
@@ -4218,8 +4218,8 @@ Warn about an invalid memory access that is found by Pointer Bounds Checker
 @opindex Wcoverage-mismatch
 Warn if feedback profiles do not match when using the
 @option{-fprofile-use} option.
-If a source file is changed between compiling with @option{-fprofile-gen} and
-with @option{-fprofile-use}, the files with the profile feedback can fail
+If a source file is changed between compiling with @option{-fprofile-generate}
+and with @option{-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.  @option{-Wno-coverage-mismatch} can be used to disable the
@@ -4823,6 +4823,23 @@ This warning is enabled by @option{-Wall}.
 @opindex Wno-missing-include-dirs
 Warn if a user-supplied include directory does not exist.
 
+@item -Wmissing-profile
+@opindex Wmissing-profile
+@opindex Wno-missing-profile
+Warn if feedback profiles are missing when using the
+@option{-fprofile-use} option.
+This option diagnoses those cases where a new function or a new file is added
+to the user code between compiling with @option{-fprofile-generate} and with
+@option{-fprofile-use}, without regenerating the profiles.  In these cases, the
+profile feedback data files do not contain any profile feedback information for
+the newly added function or file respectively.  Also, in the case when profile
+count data (.gcda) files are removed, GCC cannot use any profile feedback
+information.  In all these cases, warnings are issued to inform the user that a
+profile generation step is due.  @option{-Wno-missing-profile} can be used to
+disable the warning.  Ignoring the warning can result in poorly optimized code.
+Completely disabling the warning is not recommended and should be done only
+when non-existent profile data is justified.
+
 @item -Wmultistatement-macros
 @opindex Wmultistatement-macros
 @opindex Wno-multistatement-macros
@@ -9920,8 +9937,9 @@ Before you can use this option, you must first generate profiling information.
 
 By default, GCC emits an error message if the feedback profiles do not
 match the source code.  This error can be turned into a warning by using
-@option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
-code.
+@option{-Wno-error=coverage-mismatch}.  Note this may result in poorly
+optimized code.  Additionally, by default, GCC also emits a warning message if
+the feedback profiles do not exist (See @option{-Wmissing-profile}).
 
 If @var{path} is specified, GCC looks at the @var{path} to find
 the profile feedback data files. See @option{-fprofile-dir}.
diff --git a/gcc/testsuite/gcc.dg/Wmissing-profile.c b/gcc/testsuite/gcc.dg/Wmissing-profile.c
new file mode 100644
index 0000000..6ef1ac1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wmissing-profile.c
@@ -0,0 +1,5 @@
+/* PR gcov-profile/86957 */
+/* { dg-do compile } */
+/* { dg-options "-fprofile-use" } */
+
+void foo () { } /* { dg-warning "profile count data file not found" } */
Martin Liška Sept. 26, 2018, 9:23 a.m. UTC | #10
On 9/24/18 9:21 PM, Indu Bhagat wrote:
> Done. Attached is updated patch.

Thanks for it, I tested that right now.
You have ACK, so please install the patch. Please do not forget
to install ChangeLog entry and I would include PR entry:
https://www.gnu.org/software/gcc/contribute.html

example can be seen here:
https://github.com/gcc-mirror/gcc/blob/089d1a5f4939282881c108e0d04d026bdd82f6c6/ChangeLog#L178

Martin

> 
> Patch is tested on x86_64
> 
> Thanks
> 
> 
> On 09/24/2018 09:37 AM, Martin Sebor wrote:
>> I would suggest to use the term "remove" or "delete" instead of
>> the informal "wipe out" when referring to removing files or their
>> contents.
>>
>> Martin 
>
Richard Biener Sept. 27, 2018, 9:47 a.m. UTC | #11
On Mon, Sep 24, 2018 at 9:14 PM Indu Bhagat <indu.bhagat@oracle.com> wrote:
>
> Done. Attached is updated patch.
>
> Patch is tested on x86_64

You obviously did _not_ properly test the patch since it causes a
bunch of new testsuite
failures:

FAIL: g++.dg/pr60518.C  -std=gnu++11 (test for excess errors)
FAIL: g++.dg/pr60518.C  -std=gnu++14 (test for excess errors)
FAIL: g++.dg/pr60518.C  -std=gnu++98 (test for excess errors)
FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++11 (test for excess errors)
FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++14 (test for excess errors)
FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++98 (test for excess errors)
FAIL: g++.dg/guality/pr55665.C   -O2 -flto -fno-use-linker-plugin
-flto-partition=none  line 23 p == 40
FAIL: g++.dg/torture/pr59265.C   -O0  (test for excess errors)
FAIL: g++.dg/torture/pr59265.C   -O1  (test for excess errors)
FAIL: g++.dg/torture/pr59265.C   -O2  (test for excess errors)
FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fno-use-linker-plugin
-flto-partition=none  (test for excess errors)
FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fuse-linker-plugin
-fno-fat-lto-objects  (test for excess errors)
FAIL: g++.dg/torture/pr59265.C   -O3 -g  (test for excess errors)
FAIL: g++.dg/torture/pr59265.C   -Os  (test for excess errors)
FAIL: g++.dg/tree-prof/morefunc.C compilation,  -fprofile-use -D_PROFILE_USE
UNRESOLVED: g++.dg/tree-prof/morefunc.C execution,    -fprofile-use
-D_PROFILE_USE

and more.  Please get up to speed with GCC development and testing requirements!

Richard.

> Thanks
>
>
> On 09/24/2018 09:37 AM, Martin Sebor wrote:
> > I would suggest to use the term "remove" or "delete" instead of
> > the informal "wipe out" when referring to removing files or their
> > contents.
> >
> > Martin
>
Martin Liška Sept. 27, 2018, 10:14 a.m. UTC | #12
On 9/27/18 11:47 AM, Richard Biener wrote:
> On Mon, Sep 24, 2018 at 9:14 PM Indu Bhagat <indu.bhagat@oracle.com> wrote:
>>
>> Done. Attached is updated patch.
>>
>> Patch is tested on x86_64
> 
> You obviously did _not_ properly test the patch since it causes a
> bunch of new testsuite
> failures:
> 
> FAIL: g++.dg/pr60518.C  -std=gnu++11 (test for excess errors)
> FAIL: g++.dg/pr60518.C  -std=gnu++14 (test for excess errors)
> FAIL: g++.dg/pr60518.C  -std=gnu++98 (test for excess errors)
> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++11 (test for excess errors)
> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++14 (test for excess errors)
> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++98 (test for excess errors)
> FAIL: g++.dg/guality/pr55665.C   -O2 -flto -fno-use-linker-plugin
> -flto-partition=none  line 23 p == 40
> FAIL: g++.dg/torture/pr59265.C   -O0  (test for excess errors)
> FAIL: g++.dg/torture/pr59265.C   -O1  (test for excess errors)
> FAIL: g++.dg/torture/pr59265.C   -O2  (test for excess errors)
> FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fno-use-linker-plugin
> -flto-partition=none  (test for excess errors)
> FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fuse-linker-plugin
> -fno-fat-lto-objects  (test for excess errors)
> FAIL: g++.dg/torture/pr59265.C   -O3 -g  (test for excess errors)
> FAIL: g++.dg/torture/pr59265.C   -Os  (test for excess errors)
> FAIL: g++.dg/tree-prof/morefunc.C compilation,  -fprofile-use -D_PROFILE_USE
> UNRESOLVED: g++.dg/tree-prof/morefunc.C execution,    -fprofile-use
> -D_PROFILE_USE
> 
> and more.  Please get up to speed with GCC development and testing requirements!
> 
> Richard.

I'll cook patch for it in order to remove the failures as soon as possible.

Martin

> 
>> Thanks
>>
>>
>> On 09/24/2018 09:37 AM, Martin Sebor wrote:
>>> I would suggest to use the term "remove" or "delete" instead of
>>> the informal "wipe out" when referring to removing files or their
>>> contents.
>>>
>>> Martin
>>
Martin Liška Sept. 27, 2018, 1:10 p.m. UTC | #13
On 9/27/18 12:14 PM, Martin Liška wrote:
> On 9/27/18 11:47 AM, Richard Biener wrote:
>> On Mon, Sep 24, 2018 at 9:14 PM Indu Bhagat <indu.bhagat@oracle.com> wrote:
>>>
>>> Done. Attached is updated patch.
>>>
>>> Patch is tested on x86_64
>>
>> You obviously did _not_ properly test the patch since it causes a
>> bunch of new testsuite
>> failures:
>>
>> FAIL: g++.dg/pr60518.C  -std=gnu++11 (test for excess errors)
>> FAIL: g++.dg/pr60518.C  -std=gnu++14 (test for excess errors)
>> FAIL: g++.dg/pr60518.C  -std=gnu++98 (test for excess errors)
>> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++11 (test for excess errors)
>> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++14 (test for excess errors)
>> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++98 (test for excess errors)
>> FAIL: g++.dg/guality/pr55665.C   -O2 -flto -fno-use-linker-plugin
>> -flto-partition=none  line 23 p == 40
>> FAIL: g++.dg/torture/pr59265.C   -O0  (test for excess errors)
>> FAIL: g++.dg/torture/pr59265.C   -O1  (test for excess errors)
>> FAIL: g++.dg/torture/pr59265.C   -O2  (test for excess errors)
>> FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fno-use-linker-plugin
>> -flto-partition=none  (test for excess errors)
>> FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fuse-linker-plugin
>> -fno-fat-lto-objects  (test for excess errors)
>> FAIL: g++.dg/torture/pr59265.C   -O3 -g  (test for excess errors)
>> FAIL: g++.dg/torture/pr59265.C   -Os  (test for excess errors)
>> FAIL: g++.dg/tree-prof/morefunc.C compilation,  -fprofile-use -D_PROFILE_USE
>> UNRESOLVED: g++.dg/tree-prof/morefunc.C execution,    -fprofile-use
>> -D_PROFILE_USE
>>
>> and more.  Please get up to speed with GCC development and testing requirements!
>>
>> Richard.
> 
> I'll cook patch for it in order to remove the failures as soon as possible.
> 
> Martin
> 
>>
>>> Thanks
>>>
>>>
>>> On 09/24/2018 09:37 AM, Martin Sebor wrote:
>>>> I would suggest to use the term "remove" or "delete" instead of
>>>> the informal "wipe out" when referring to removing files or their
>>>> contents.
>>>>
>>>> Martin
>>>
> 

There's tested patch that I made. It's tested on x86_64-linux-gnu. Feel free
to install it after approval. I'll be back on Monday.

Martin
From 1757b63f13e0f18bab4be90001e1056069f8799a Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 27 Sep 2018 12:14:09 +0200
Subject: [PATCH] Fix fallout of -Wmissing-profile warning.

gcc/ChangeLog:

2018-09-27  Martin Liska  <mliska@suse.cz>

	* coverage.c (get_coverage_counts): Revert the formatting
	of missing profile opt info.

gcc/testsuite/ChangeLog:

2018-09-27  Martin Liska  <mliska@suse.cz>

	* g++.dg/pr60518.C: Add -Wno-missing-profile.
	* g++.dg/torture/pr59265.C: Likewise.
	* g++.dg/tree-prof/morefunc.C: Likewise.
	* g++.dg/tree-ssa/dom-invalid.C: Likewise.
	* gcc.dg/pr26570.c: Likewise.
	* gcc.dg/pr32773.c: Likewise.
	* gcc.dg/pr40209.c: Likewise.
	* gcc.dg/pr51957-1.c: Likewise.
	* gcc.dg/pr80747.c: Likewise.
	* gcc.target/aarch64/pr62262.c: Likewise.
---
 gcc/coverage.c                              | 10 ++++------
 gcc/testsuite/g++.dg/pr60518.C              |  2 +-
 gcc/testsuite/g++.dg/torture/pr59265.C      |  2 +-
 gcc/testsuite/g++.dg/tree-prof/morefunc.C   |  2 +-
 gcc/testsuite/g++.dg/tree-ssa/dom-invalid.C |  2 +-
 gcc/testsuite/gcc.dg/pr26570.c              |  2 +-
 gcc/testsuite/gcc.dg/pr32773.c              |  4 ++--
 gcc/testsuite/gcc.dg/pr40209.c              |  2 +-
 gcc/testsuite/gcc.dg/pr51957-1.c            |  2 +-
 gcc/testsuite/gcc.dg/pr80747.c              |  2 +-
 gcc/testsuite/gcc.target/aarch64/pr62262.c  |  2 +-
 11 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 19c696c3493..6b45ce9085b 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -314,12 +314,10 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
 	      dump_user_location_t loc
 		= dump_user_location_t::from_location_t (input_location);
 	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
-			       "file %s not found\n",
-			       da_file_name);
-	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
-			   (flag_guess_branch_prob
-			    ? "execution counts estimated\n"
-			    : "execution counts assumed to be zero\n"));
+			       "file %s not found, %s\n", da_file_name,
+			       (flag_guess_branch_prob
+				? "execution counts estimated"
+				: "execution counts assumed to be zero"));
 	    }
 	}
       return NULL;
diff --git a/gcc/testsuite/g++.dg/pr60518.C b/gcc/testsuite/g++.dg/pr60518.C
index e3da48a2ec9..e4a80da29ee 100644
--- a/gcc/testsuite/g++.dg/pr60518.C
+++ b/gcc/testsuite/g++.dg/pr60518.C
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options "-Os -fprofile-use" }
+// { dg-options "-Os -fprofile-use -Wno-missing-profile" }
 
 int a;
 int fn1 () { return a == ',' || a == ';'; }
diff --git a/gcc/testsuite/g++.dg/torture/pr59265.C b/gcc/testsuite/g++.dg/torture/pr59265.C
index d48efe59395..f3dceb929d2 100644
--- a/gcc/testsuite/g++.dg/torture/pr59265.C
+++ b/gcc/testsuite/g++.dg/torture/pr59265.C
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options "-fprofile-use -std=gnu++11 -Wno-return-type" }
+// { dg-options "-fprofile-use -std=gnu++11 -Wno-return-type -Wno-missing-profile" }
 
 class A {
   int m_fn1() const;
diff --git a/gcc/testsuite/g++.dg/tree-prof/morefunc.C b/gcc/testsuite/g++.dg/tree-prof/morefunc.C
index 2e3fc114758..a9bdc167f45 100644
--- a/gcc/testsuite/g++.dg/tree-prof/morefunc.C
+++ b/gcc/testsuite/g++.dg/tree-prof/morefunc.C
@@ -1,4 +1,4 @@
-/* { dg-options "-O2 -fno-devirtualize --param=profile-func-internal-id=0 -fdump-ipa-profile -fdump-ipa-afdo -Wno-attributes -Wno-coverage-mismatch" } */
+/* { dg-options "-O2 -fno-devirtualize --param=profile-func-internal-id=0 -fdump-ipa-profile -fdump-ipa-afdo -Wno-attributes -Wno-coverage-mismatch -Wno-missing-profile" } */
 #include "reorder_class1.h"
 #include "reorder_class2.h"
 
diff --git a/gcc/testsuite/g++.dg/tree-ssa/dom-invalid.C b/gcc/testsuite/g++.dg/tree-ssa/dom-invalid.C
index 41343ee4206..3c01383f809 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/dom-invalid.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/dom-invalid.C
@@ -1,7 +1,7 @@
 // PR tree-optimization/39557
 // invalid post-dom info leads to infinite loop
 // { dg-do run }
-// { dg-options "-Wall -fno-exceptions -O2 -fprofile-use -fopt-info -fno-rtti" }
+// { dg-options "-Wall -fno-exceptions -O2 -fprofile-use -fopt-info -fno-rtti -Wno-missing-profile" }
 
 struct C
 {
diff --git a/gcc/testsuite/gcc.dg/pr26570.c b/gcc/testsuite/gcc.dg/pr26570.c
index 8ce8a4465e8..007076f9659 100644
--- a/gcc/testsuite/gcc.dg/pr26570.c
+++ b/gcc/testsuite/gcc.dg/pr26570.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fprofile-generate -fprofile-use -fopt-info" } */
+/* { dg-options "-O2 -fprofile-generate -fprofile-use -fopt-info -Wno-missing-profile" } */
 /* { dg-require-profiling "-fprofile-generate" } */
 
 unsigned test (unsigned a, unsigned b)
diff --git a/gcc/testsuite/gcc.dg/pr32773.c b/gcc/testsuite/gcc.dg/pr32773.c
index 19a90195ad3..fe046d9fe47 100644
--- a/gcc/testsuite/gcc.dg/pr32773.c
+++ b/gcc/testsuite/gcc.dg/pr32773.c
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fprofile-use -fopt-info" } */
-/* { dg-options "-O -m4 -fprofile-use -fopt-info" { target sh-*-* } } */
+/* { dg-options "-O -fprofile-use -fopt-info -Wno-missing-profile" } */
+/* { dg-options "-O -m4 -fprofile-use -fopt-info -Wno-missing-profile" { target sh-*-* } } */
 
 void foo (int *p)
 {
diff --git a/gcc/testsuite/gcc.dg/pr40209.c b/gcc/testsuite/gcc.dg/pr40209.c
index afe131fc5eb..4e77df5c2e6 100644
--- a/gcc/testsuite/gcc.dg/pr40209.c
+++ b/gcc/testsuite/gcc.dg/pr40209.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fprofile-use -fopt-info" } */
+/* { dg-options "-O2 -fprofile-use -fopt-info -Wno-missing-profile" } */
 
 void process(const char *s);
 
diff --git a/gcc/testsuite/gcc.dg/pr51957-1.c b/gcc/testsuite/gcc.dg/pr51957-1.c
index d899771ad00..d6712b5be2a 100644
--- a/gcc/testsuite/gcc.dg/pr51957-1.c
+++ b/gcc/testsuite/gcc.dg/pr51957-1.c
@@ -1,6 +1,6 @@
 /* PR target/51957 */
 /* { dg-do link } */
-/* { dg-options "-O2 -g -fprofile-use" } */
+/* { dg-options "-O2 -g -fprofile-use -Wno-missing-profile" } */
 /* { dg-additional-sources "pr51957-2.c" } */
 
 int v[128];
diff --git a/gcc/testsuite/gcc.dg/pr80747.c b/gcc/testsuite/gcc.dg/pr80747.c
index ea9dd3c3033..8befab2ab1c 100644
--- a/gcc/testsuite/gcc.dg/pr80747.c
+++ b/gcc/testsuite/gcc.dg/pr80747.c
@@ -1,6 +1,6 @@
 /* PR rtl-optimization/80747 */
 /* { dg-do compile } */
-/* { dg-options "-fprofile-use -freorder-blocks-and-partition -O1 -foptimize-sibling-calls" } */
+/* { dg-options "-fprofile-use -freorder-blocks-and-partition -O1 -foptimize-sibling-calls -Wno-missing-profile" } */
 
 int
 foo (int a)
diff --git a/gcc/testsuite/gcc.target/aarch64/pr62262.c b/gcc/testsuite/gcc.target/aarch64/pr62262.c
index 5bf90bf7fe3..6edb3c73c6b 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr62262.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr62262.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fprofile-use" } */
+/* { dg-options "-O2 -fprofile-use -Wno-missing-profile" } */
 
 static inline int CLZ(int mask) {
    return mask ? __builtin_clz(mask) : 32;
Richard Biener Sept. 27, 2018, 2:53 p.m. UTC | #14
On Thu, Sep 27, 2018 at 3:10 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 9/27/18 12:14 PM, Martin Liška wrote:
> > On 9/27/18 11:47 AM, Richard Biener wrote:
> >> On Mon, Sep 24, 2018 at 9:14 PM Indu Bhagat <indu.bhagat@oracle.com> wrote:
> >>>
> >>> Done. Attached is updated patch.
> >>>
> >>> Patch is tested on x86_64
> >>
> >> You obviously did _not_ properly test the patch since it causes a
> >> bunch of new testsuite
> >> failures:
> >>
> >> FAIL: g++.dg/pr60518.C  -std=gnu++11 (test for excess errors)
> >> FAIL: g++.dg/pr60518.C  -std=gnu++14 (test for excess errors)
> >> FAIL: g++.dg/pr60518.C  -std=gnu++98 (test for excess errors)
> >> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++11 (test for excess errors)
> >> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++14 (test for excess errors)
> >> FAIL: g++.dg/tree-ssa/dom-invalid.C  -std=gnu++98 (test for excess errors)
> >> FAIL: g++.dg/guality/pr55665.C   -O2 -flto -fno-use-linker-plugin
> >> -flto-partition=none  line 23 p == 40
> >> FAIL: g++.dg/torture/pr59265.C   -O0  (test for excess errors)
> >> FAIL: g++.dg/torture/pr59265.C   -O1  (test for excess errors)
> >> FAIL: g++.dg/torture/pr59265.C   -O2  (test for excess errors)
> >> FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fno-use-linker-plugin
> >> -flto-partition=none  (test for excess errors)
> >> FAIL: g++.dg/torture/pr59265.C   -O2 -flto -fuse-linker-plugin
> >> -fno-fat-lto-objects  (test for excess errors)
> >> FAIL: g++.dg/torture/pr59265.C   -O3 -g  (test for excess errors)
> >> FAIL: g++.dg/torture/pr59265.C   -Os  (test for excess errors)
> >> FAIL: g++.dg/tree-prof/morefunc.C compilation,  -fprofile-use -D_PROFILE_USE
> >> UNRESOLVED: g++.dg/tree-prof/morefunc.C execution,    -fprofile-use
> >> -D_PROFILE_USE
> >>
> >> and more.  Please get up to speed with GCC development and testing requirements!
> >>
> >> Richard.
> >
> > I'll cook patch for it in order to remove the failures as soon as possible.
> >
> > Martin
> >
> >>
> >>> Thanks
> >>>
> >>>
> >>> On 09/24/2018 09:37 AM, Martin Sebor wrote:
> >>>> I would suggest to use the term "remove" or "delete" instead of
> >>>> the informal "wipe out" when referring to removing files or their
> >>>> contents.
> >>>>
> >>>> Martin
> >>>
> >
>
> There's tested patch that I made. It's tested on x86_64-linux-gnu. Feel free
> to install it after approval. I'll be back on Monday.

Patch is OK (and I installed it).

Richard.

> Martin
Thomas Schwinge Dec. 5, 2018, 11:33 a.m. UTC | #15
Hi!

Sorry for my late follow-up; had a lot of catch up to do back then.

On Thu, 27 Sep 2018 11:47:31 +0200, Richard Biener <richard.guenther@gmail.com> wrote:
> On Mon, Sep 24, 2018 at 9:14 PM Indu Bhagat <indu.bhagat@oracle.com> wrote:
> >
> > Done. Attached is updated patch.
> >
> > Patch is tested on x86_64
> 
> You obviously did _not_ properly test the patch since it causes a
> bunch of new testsuite
> failures: [...]
> 
> and more.  Please get up to speed with GCC development and testing requirements!

Also, with this commit, several test cases regressed from PASS to
UNSUPPORTED because of "{ dg-require-effective-target freorder }" running
into:

    fprofile_use_freorder16732.c: In function 'void foo()':
    fprofile_use_freorder16732.c:2:20: warning: '[...]/gcc/testsuite/g++/fprofile_use_freorder16732.gcda' profile count data file not found [-Wmissing-profile]

Iain had just mentioned that in <https://gcc.gnu.org/PR88310>, and fixed
in r266785, <https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00209.html>.
(Back then, I had produced the same fix, but not yet posted.)  :-|

With "{ dg-require-effective-target freorder }" thusly restored, I then
also saw two other regressions/FAILs, back then:

    [-UNSUPPORTED: g++.dg/tree-prof/pr63581.C-]
    UNSUPPORTED: g++.dg/tree-prof/pr63581.C -fauto-profile
    {+PASS: g++.dg/tree-prof/pr63581.C compilation,  -fprofile-generate -D_PROFILE_GENERATE+}
    {+FAIL: g++.dg/tree-prof/pr63581.C compilation,  -fprofile-use -D_PROFILE_USE+}
    {+PASS: g++.dg/tree-prof/pr63581.C execution,    -fprofile-generate -D_PROFILE_GENERATE+}
    {+UNRESOLVED: g++.dg/tree-prof/pr63581.C execution,    -fprofile-use -D_PROFILE_USE+}
    
    [...]/gcc/testsuite/g++.dg/tree-prof/pr63581.C: In function 'int uptodate(page*)':
    [...]/gcc/testsuite/g++.dg/tree-prof/pr63581.C:28:19: warning: profile for function 'int uptodate(page*)' not found in profile data [-Wmissing-profile]

..., and:

    [-UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c-]
    UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c -fauto-profile
    {+PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -fprofile-generate -D_PROFILE_GENERATE+}
    {+FAIL: gcc.dg/tree-prof/20041218-1.c compilation,  -fprofile-use -D_PROFILE_USE+}
    {+PASS: gcc.dg/tree-prof/20041218-1.c execution,    -fprofile-generate -D_PROFILE_GENERATE+}
    {+UNRESOLVED: gcc.dg/tree-prof/20041218-1.c execution,    -fprofile-use -D_PROFILE_USE+}
    
    [...]/gcc/testsuite/gcc.dg/tree-prof/20041218-1.c: In function 'bar':
    [...]/gcc/testsuite/gcc.dg/tree-prof/20041218-1.c:58:1: warning: profile for function 'bar' not found in profile data [-Wmissing-profile]

..., for which I came up with the following patch.

But, this doesn't now seem to be necessary anymore, or am I confused?
Maybe this got fixed differently -- or is anybody still seeing these
FAILs?  (If not, then I'm not proposing to commit this, of course.)

commit 04ad00f79075a0c5eff1f806959918081e54684c
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Wed Oct 31 23:29:32 2018 +0100

    Avoid two -Wmissing-profile diagnostics
---
 gcc/testsuite/g++.dg/tree-prof/pr63581.C    |    5 +++++
 gcc/testsuite/gcc.dg/tree-prof/20041218-1.c |    5 +++++
 2 files changed, 10 insertions(+)

diff --git gcc/testsuite/g++.dg/tree-prof/pr63581.C gcc/testsuite/g++.dg/tree-prof/pr63581.C
index c8caf07..9800851 100644
--- gcc/testsuite/g++.dg/tree-prof/pr63581.C
+++ gcc/testsuite/g++.dg/tree-prof/pr63581.C
@@ -25,10 +25,15 @@ __attribute__((noinline)) static int zero (void)
   return ii;
 }
 
+#pragma GCC diagnostic push
+/* WARNING: profopt.exp does not support dg-warning */
+/* "profile for function 'int uptodate(page*)' not found in profile data" */
+#pragma GCC diagnostic ignored "-Wmissing-profile"
 static inline int uptodate (struct page* p)
 {
   return (p->i < 709);
 }
+#pragma GCC diagnostic pop
 
 static struct page* bar(int i)
 {
diff --git gcc/testsuite/gcc.dg/tree-prof/20041218-1.c gcc/testsuite/gcc.dg/tree-prof/20041218-1.c
index cbd1c7c..41c60a7 100644
--- gcc/testsuite/gcc.dg/tree-prof/20041218-1.c
+++ gcc/testsuite/gcc.dg/tree-prof/20041218-1.c
@@ -54,6 +54,10 @@ check (void *x, struct S *y)
   return 1;
 }
 
+#pragma GCC diagnostic push
+/* WARNING: profopt.exp does not support dg-warning */
+/* "profile for function 'bar' not found in profile data" */
+#pragma GCC diagnostic ignored "-Wmissing-profile"
 static struct V *
 bar (unsigned int x, void *y)
 {
@@ -75,6 +79,7 @@ bar (unsigned int x, void *y)
     return (void *) 0;
   return u;
 }
+#pragma GCC diagnostic pop
 
 int
 foo (unsigned int *x, unsigned int y, void **z)


Grüße
 Thomas
Indu Bhagat Dec. 7, 2018, 1:54 a.m. UTC | #16
On 12/05/2018 03:33 AM, Thomas Schwinge wrote:
> Hi!
>
> Sorry for my late follow-up; had a lot of catch up to do back then.
>
> On Thu, 27 Sep 2018 11:47:31 +0200, Richard Biener<richard.guenther@gmail.com>  wrote:
>> On Mon, Sep 24, 2018 at 9:14 PM Indu Bhagat<indu.bhagat@oracle.com>  wrote:
>>> Done. Attached is updated patch.
>>>
>>> Patch is tested on x86_64
>> You obviously did_not_  properly test the patch since it causes a
>> bunch of new testsuite
>> failures: [...]
>>
>> and more.  Please get up to speed with GCC development and testing requirements!
> Also, with this commit, several test cases regressed from PASS to
> UNSUPPORTED because of "{ dg-require-effective-target freorder }" running
> into:
>
>      fprofile_use_freorder16732.c: In function 'void foo()':
>      fprofile_use_freorder16732.c:2:20: warning: '[...]/gcc/testsuite/g++/fprofile_use_freorder16732.gcda' profile count data file not found [-Wmissing-profile]
>
> Iain had just mentioned that in<https://gcc.gnu.org/PR88310>, and fixed
> in r266785,<https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00209.html>.
> (Back then, I had produced the same fix, but not yet posted.)  :-|
>
> With "{ dg-require-effective-target freorder }" thusly restored, I then
> also saw two other regressions/FAILs, back then:
>
>      [-UNSUPPORTED: g++.dg/tree-prof/pr63581.C-]
>      UNSUPPORTED: g++.dg/tree-prof/pr63581.C -fauto-profile
>      {+PASS: g++.dg/tree-prof/pr63581.C compilation,  -fprofile-generate -D_PROFILE_GENERATE+}
>      {+FAIL: g++.dg/tree-prof/pr63581.C compilation,  -fprofile-use -D_PROFILE_USE+}
>      {+PASS: g++.dg/tree-prof/pr63581.C execution,    -fprofile-generate -D_PROFILE_GENERATE+}
>      {+UNRESOLVED: g++.dg/tree-prof/pr63581.C execution,    -fprofile-use -D_PROFILE_USE+}
>      
>      [...]/gcc/testsuite/g++.dg/tree-prof/pr63581.C: In function 'int uptodate(page*)':
>      [...]/gcc/testsuite/g++.dg/tree-prof/pr63581.C:28:19: warning: profile for function 'int uptodate(page*)' not found in profile data [-Wmissing-profile]
>
> ..., and:
>
>      [-UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c-]
>      UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c -fauto-profile
>      {+PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -fprofile-generate -D_PROFILE_GENERATE+}
>      {+FAIL: gcc.dg/tree-prof/20041218-1.c compilation,  -fprofile-use -D_PROFILE_USE+}
>      {+PASS: gcc.dg/tree-prof/20041218-1.c execution,    -fprofile-generate -D_PROFILE_GENERATE+}
>      {+UNRESOLVED: gcc.dg/tree-prof/20041218-1.c execution,    -fprofile-use -D_PROFILE_USE+}
>      
>      [...]/gcc/testsuite/gcc.dg/tree-prof/20041218-1.c: In function 'bar':
>      [...]/gcc/testsuite/gcc.dg/tree-prof/20041218-1.c:58:1: warning: profile for function 'bar' not found in profile data [-Wmissing-profile]
>
> ..., for which I came up with the following patch.
>
> But, this doesn't now seem to be necessary anymore, or am I confused?
> Maybe this got fixed differently -- or is anybody still seeing these
> FAILs?  (If not, then I'm not proposing to commit this, of course.)

I tested the trunk as of commit 85df98d7fbb6ef5c5b6e97190fff4028f4b70747
(Dec 5 PR c/87028) with and without the -Wmissing-profile on by default
in the compiler. I.e., with the following change :

Common Var(warn_missing_profile) Init(1) Warning
+Common Var(warn_missing_profile) Init(0) Warning

Two observations :
1. The two issues (tree-prof/pr63581.C and tree-prof/20041218-1.c) that you run
    into are not repeatable on my end. I am not sure why you run into them.

2. I do however see other tests (a total of 23) which are have regressed from
    PASS --> UNRESOLVED. A diff is attached.

    Each one of them is due to "Error/Warning threshold exceeded:  1 0 (max. 1 3)"

E.g.,
ERROR: gcc.dg/tree-prof/20050826-2.c: error executing dg-final-use: couldn't open "20050826-2.c.116t.dom2 20050826-2.c.115t.dom2": no such file or directory
   Error/Warning threshold exceeded:  1 0 (max. 1 3)

(I have not been able to see the -Wmissing-profile warning explicitly in my logs
  yet. I was thinking a RUNTESTFLAGS="-v -v -v" should have helped, but it didnt.)

Any suggestions to resolve these tests are appreciated. I am not sure yet of the
most maintainable way to "allow the warning in all tests that it appears". I
need to look around a bit (Is Thomas' patch doing just what needs to be done here ?).

Thanks
Indu
UNRESOLVED: c-c++-common/unroll-1.c  -Wc++-compat : error executing dg-final: couldn't open "unroll-1.c.250r.loop2_unroll unroll-1.c.251r.loop2_unroll": no such file or directory
UNRESOLVED: gcc.dg/ipa/ipa-icf-38.c: error executing dg-final: couldn't open "ipa-icf-38.exe.wpa.069i.icf ipa-icf-38.exe.wpa.070i.icf": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/20050826-2.c: Error executing dg-final-use: couldn't open "20050826-2.c.116t.dom2 20050826-2.c.115t.dom2": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/cmpsf-1.c: Error executing dg-final-use: couldn't open "cmpsf-1.c.115t.dom2 cmpsf-1.c.116t.dom2": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/inliner-1.c: Error executing dg-final-use: couldn't open "inliner-1.c.229t.optimized inliner-1.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/merge_block.c: Error executing dg-final-use: couldn't open "merge_block.c.229t.optimized merge_block.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/peel-1.c: Error executing dg-final-use: couldn't open "peel-1.c.160t.cunroll peel-1.c.159t.cunroll": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/pr77698.c: Error executing dg-final-use: couldn't open "pr77698.c.304r.alignments pr77698.c.302r.alignments pr77698.c.303r.alignments": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/stringop-1.c: Error executing dg-final-use: couldn't open "stringop-1.c.229t.optimized stringop-1.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/stringop-2.c: Error executing dg-final-use: couldn't open "stringop-2.c.229t.optimized stringop-2.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/unroll-1.c: Error executing dg-final-use: couldn't open "unroll-1.c.250r.loop2_unroll unroll-1.c.251r.loop2_unroll": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/update-cunroll-2.c: Error executing dg-final-use: couldn't open "update-cunroll-2.c.229t.optimized update-cunroll-2.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/update-loopch.c: Error executing dg-final-use: couldn't open "update-loopch.c.169t.switchlower1 update-loopch.c.170t.switchlower1": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/update-tailcall.c: Error executing dg-final-use: couldn't open "update-tailcall.c.190t.tailc update-tailcall.c.191t.tailc": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-10.c: Error executing dg-final-use: couldn't open "val-prof-10.c.232r.expand val-prof-10.c.231r.expand": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-2.c: Error executing dg-final-use: couldn't open "val-prof-2.c.229t.optimized val-prof-2.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-3.c: Error executing dg-final-use: couldn't open "val-prof-3.c.229t.optimized val-prof-3.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-4.c: Error executing dg-final-use: couldn't open "val-prof-4.c.229t.optimized val-prof-4.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-5.c: Error executing dg-final-use: couldn't open "val-prof-5.c.230t.optimized val-prof-5.c.229t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-6.c: Error executing dg-final-use: couldn't open "val-prof-6.c.229t.optimized val-prof-6.c.230t.optimized": no such file or directory
UNRESOLVED: gcc.dg/tree-prof/val-prof-9.c: Error executing dg-final-use: couldn't open "val-prof-9.c.230t.optimized val-prof-9.c.229t.optimized": no such file or directory
UNRESOLVED: g++.dg/tree-prof/indir-call-prof.C: Error executing dg-final-use: couldn't open "indir-call-prof.C.230t.optimized indir-call-prof.C.229t.optimized": no such file or directory
UNRESOLVED: g++.dg/tree-prof/pr35545.C: Error executing dg-final-use: couldn't open "pr35545.C.069i.profile_estimate pr35545.C.068i.profile_estimate": no such file or directory
Indu Bhagat Dec. 10, 2018, 8:54 p.m. UTC | #17
On 12/06/2018 05:54 PM, Indu Bhagat wrote:
> 2. I do however see other tests (a total of 23) which are have 
> regressed from
>    PASS --> UNRESOLVED. A diff is attached.
>
>    Each one of them is due to "Error/Warning threshold exceeded: 1 0 
> (max. 1 3)"
False alarm.

Looks like there is some flakiness I ran into.

New testsuite runs (make check-gcc) on a fresh builds of the GCC (with 
and without missing-profile) enabled look OK.
One additional failure as expected (Wmissing-profile.c). No additional 
unresolved tests.

Indu
Thomas Schwinge Dec. 11, 2018, 9:14 a.m. UTC | #18
Hi Indu!

I recently saw that you just started contributing to GCC, so: welcome,
and enjoy to journey!

On Mon, 10 Dec 2018 12:54:09 -0800, Indu Bhagat <indu.bhagat@oracle.com> wrote:
> On 12/06/2018 05:54 PM, Indu Bhagat wrote:
> > [...]

Thanks for looking into this issue again.  As I said in private email,
such things (like looking at the wrong build's test logs) happen to all
of us.  As long as we learn -- or, at least try to learn ;-) -- something
from that, that's fine, as far as I'm concerned.

Evidently, the peer review/collaboration that we have in these Free
Software/Open Source software projects worked, and we eventually caught
this issue.  :-)

> > 2. I do however see other tests (a total of 23) which are have 
> > regressed from
> >    PASS --> UNRESOLVED. A diff is attached.
> >
> >    Each one of them is due to "Error/Warning threshold exceeded: 1 0 
> > (max. 1 3)"
> False alarm.
> 
> Looks like there is some flakiness I ran into.

Anything we could help you with, or that you have questions about?

> New testsuite runs (make check-gcc) on a fresh builds of the GCC (with 
> and without missing-profile) enabled look OK.
> One additional failure as expected (Wmissing-profile.c). No additional 
> unresolved tests.

Good, thanks for verifying!


Grüße
 Thomas
diff mbox series

Patch

diff --git a/gcc/common.opt b/gcc/common.opt
index ebc3ef4..d93ddca 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -811,6 +811,10 @@  Wcoverage-mismatch
 Common Var(warn_coverage_mismatch) Init(1) Warning
 Warn in case profiles in -fprofile-use do not match.
 
+Wmissing-profile
+Common Var(warn_missing_profile) Init(1) Warning
+Warn in case profiles in -fprofile-use do not exist.
+
 Wvector-operation-performance
 Common Var(warn_vector_operation_performance) Warning
 Warn when a vector operation is compiled outside the SIMD.
diff --git a/gcc/coverage.c b/gcc/coverage.c
index bae6f5c..df031df 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -341,16 +341,24 @@  get_coverage_counts (unsigned counter, unsigned expected,
     {
       static int warned = 0;
 
-      if (!warned++ && dump_enabled_p ())
+      if (!warned++)
 	{
-	  dump_user_location_t loc
-	    = dump_user_location_t::from_location_t (input_location);
-	  dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+	  warning (OPT_Wmissing_profile,
+		   "%qs profile count data file not found,"
+		   " regenerating profiles may help",
+		   da_file_name);
+	  if (dump_enabled_p ())
+	    {
+	      dump_user_location_t loc
+		= dump_user_location_t::from_location_t (input_location);
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
+			       "file %s not found\n",
+			       da_file_name);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
 			   (flag_guess_branch_prob
-			    ? "file %s not found, execution counts estimated\n"
-			    : "file %s not found, execution counts assumed to "
-			    "be zero\n"),
-			   da_file_name);
+			    ? "execution counts estimated\n"
+			    : "execution counts assumed to be zero\n"));
+	    }
 	}
       return NULL;
     }
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ca92028..e62bcae 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -314,7 +314,7 @@  Objective-C and Objective-C++ Dialects}.
 -Wlogical-op  -Wlogical-not-parentheses  -Wlong-long @gol
 -Wmain  -Wmaybe-uninitialized  -Wmemset-elt-size  -Wmemset-transposed-args @gol
 -Wmisleading-indentation  -Wmissing-attributes -Wmissing-braces @gol
--Wmissing-field-initializers  -Wmissing-include-dirs @gol
+-Wmissing-field-initializers  -Wmissing-include-dirs  -Wmissing-profile @gol
 -Wno-multichar  -Wmultistatement-macros  -Wnonnull  -Wnonnull-compare @gol
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]} @gol
 -Wnull-dereference  -Wodr  -Wno-overflow  -Wopenmp-simd  @gol
@@ -4816,6 +4816,25 @@  This warning is enabled by @option{-Wall}.
 @opindex Wno-missing-include-dirs
 Warn if a user-supplied include directory does not exist.
 
+@item -Wmissing-profile
+@opindex Wmissing-profile
+@opindex Wno-missing-profile
+Warn if feedback profiles are missing when using the
+@option{-fprofile-use} option.
+If a new function or a new file is added to the user code between compiling
+with @option{-fprofile-gen} and with @option{-fprofile-use} without
+regenerating the profiles, the profile feedback data files do not contain any
+profile feedback information for the newly
+added function or file respectively.  Also, in the case when profile count data
+(.gcda) files are wiped out, GCC cannot use any profile feedback
+information.  In all these cases, warnings are issued to inform the user that a
+profile generation step is due.  By default, this warning is enabled and is
+treated as an error.  @option{-Wno-missing-profile} can be used to disable the
+warning or @option{-Wno-error=missing-profile} 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 cases when non-existent profile data is
+justified.  Completely disabling the warning is not recommended.
+
 @item -Wmultistatement-macros
 @opindex Wmultistatement-macros
 @opindex Wno-multistatement-macros
@@ -9899,8 +9918,10 @@  Before you can use this option, you must first generate profiling information.
 
 By default, GCC emits an error message if the feedback profiles do not
 match the source code.  This error can be turned into a warning by using
-@option{-Wcoverage-mismatch}.  Note this may result in poorly optimized
-code.
+@option{-Wno-error=coverage-mismatch}.  Note this may result in poorly
+optimized code.  Additionally, by default, GCC also emits an error message if
+the feedback profiles do not exist.  The latter error can be turned into a
+warning by using @option{-Wno-error=missing-profile}.
 
 If @var{path} is specified, GCC looks at the @var{path} to find
 the profile feedback data files. See @option{-fprofile-dir}.
diff --git a/gcc/profile.c b/gcc/profile.c
index cb51e0d..40f9763 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -286,7 +286,13 @@  get_exec_counts (unsigned cfg_checksum, unsigned lineno_checksum)
   counts = get_coverage_counts (GCOV_COUNTER_ARCS, num_edges, cfg_checksum,
 				lineno_checksum, &profile_info);
   if (!counts)
-    return NULL;
+    {
+      warning (OPT_Wmissing_profile,
+	       "profile for function %qE not found in profile data,"
+	       " regenerating profiles may help",
+	       DECL_ASSEMBLER_NAME (current_function_decl));
+      return NULL;
+    }
 
   get_working_sets ();
 
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 9fb83d4..5891554 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1782,14 +1782,24 @@  process_options (void)
       || !targetm.have_prologue () || !targetm.have_epilogue ())
     flag_ipa_ra = 0;
 
-  /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
-     have not been set.  */
-  if (!global_options_set.x_warnings_are_errors
-      && warn_coverage_mismatch
-      && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
-          DK_UNSPECIFIED))
-    diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
-                                    DK_ERROR, UNKNOWN_LOCATION);
+  if (!global_options_set.x_warnings_are_errors)
+    {
+      /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
+	 have not been set.  */
+      if (warn_coverage_mismatch
+	  && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
+	      DK_UNSPECIFIED))
+	diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
+					DK_ERROR, UNKNOWN_LOCATION);
+
+      /* Enable -Werror=missing-profile when -Werror and -Wno-error
+	 have not been set.  */
+      if (warn_missing_profile
+	  && (global_dc->classify_diagnostic[OPT_Wmissing_profile] ==
+	      DK_UNSPECIFIED))
+	diagnostic_classify_diagnostic (global_dc, OPT_Wmissing_profile,
+					DK_ERROR, UNKNOWN_LOCATION);
+    }
 
   /* Save the current optimization options.  */
   optimization_default_node = build_optimization_node (&global_options);