This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Don't error on coverage mismatch by request


On 1/22/07, Richard Guenther <richard.guenther@gmail.com> wrote:

Ok, with this I managed to create a testcase that checks for properly
not-erroring.
But only with providing '-w' and silencing the extra inform () calls
in coverage.c
for inbibit_warnings==1.  As we do not support dg-error or dg-warning
for tree-prof.exp,
nor do we support an XFAIL somewhere (so I could declare profile
mismatch without
-Wcoverage-mismatch xfail...)

Maybe better than nothing?

Richard.

2007-01-20 Richard Guenther <rguenther@suse.de>

        * doc/invoke.texi (-Wcoverage-mismatch): Document.
        * common.opt (-Wcoverage-mismatch): New warning option.
        * coverage.c (get_coverage_counts): Ignore coverage mismatch
        if -Wcoverage-mismatch is given.

        * gcc.dg/tree-prof/tree-prof.exp: Define _PROFILE_GENERATE
        and _PROFILE_USE.
        * gcc.dg/tree-prof/wcoverage-mismatch-1.c: New failing testcase.
        * gcc.dg/tree-prof/wcoverage-mismatch-2.c: New testcase.

(this time with patch)
2007-01-20  Richard Guenther  <rguenther@suse.de>

	* doc/invoke.texi (-Wcoverage-mismatch): Document.
	* common.opt (-Wcoverage-mismatch): New warning option.
	* coverage.c (get_coverage_counts): Ignore coverage mismatch
	if -Wcoverage-mismatch is given.

	* gcc.dg/tree-prof/tree-prof.exp: Define _PROFILE_GENERATE
	and _PROFILE_USE.
	* gcc.dg/tree-prof/wcoverage-mismatch-1.c: New failing testcase.
	* gcc.dg/tree-prof/wcoverage-mismatch-2.c: New testcase.

Index: gcc/common.opt
===================================================================
*** gcc.orig/common.opt	2007-01-22 11:02:08.000000000 +0100
--- gcc/common.opt	2007-01-22 11:25:45.000000000 +0100
*************** Wvolatile-register-var
*** 197,202 ****
--- 197,206 ----
  Common Var(warn_register_var)
  Warn when a register variable is declared volatile
  
+ Wcoverage-mismatch
+ Common RejectNegative Var(warn_coverage_mismatch)
+ Warn instead of error in case profiles in -fprofile-use do not match
+ 
  aux-info
  Common Separate
  -aux-info <file>	Emit declaration information into <file>
Index: gcc/coverage.c
===================================================================
*** gcc.orig/coverage.c	2006-11-01 12:36:57.000000000 +0100
--- gcc/coverage.c	2007-01-22 14:43:19.000000000 +0100
*************** get_coverage_counts (unsigned counter, u
*** 347,371 ****
      {
        warning (0, "no coverage for function %qs found", IDENTIFIER_POINTER
  	       (DECL_ASSEMBLER_NAME (current_function_decl)));
!       return 0;
      }
  
    checksum = compute_checksum ();
!   if (entry->checksum != checksum)
      {
!       error ("coverage mismatch for function %qs while reading counter %qs",
! 	     IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)),
! 	     ctr_names[counter]);
!       error ("checksum is %x instead of %x", entry->checksum, checksum);
!       return 0;
!     }
!   else if (entry->summary.num != expected)
!     {
!       error ("coverage mismatch for function %qs while reading counter %qs",
! 	     IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)),
! 	     ctr_names[counter]);
!       error ("number of counters is %d instead of %d", entry->summary.num, expected);
!       return 0;
      }
  
    if (summary)
--- 347,392 ----
      {
        warning (0, "no coverage for function %qs found", IDENTIFIER_POINTER
  	       (DECL_ASSEMBLER_NAME (current_function_decl)));
!       return NULL;
      }
  
    checksum = compute_checksum ();
!   if (entry->checksum != checksum
!       || entry->summary.num != expected)
      {
!       static int warned = 0;
!       const char *id = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME
! 			 (current_function_decl));
! 
!       if (warn_coverage_mismatch)
! 	warning (OPT_Wcoverage_mismatch, "coverage mismatch for function "
! 		 "%qs while reading counter %qs", id, ctr_names[counter]);
!       else
! 	error ("coverage mismatch for function %qs while reading counter %qs",
! 	       id, ctr_names[counter]);
! 
!       if (!inhibit_warnings)
! 	{
! 	  if (entry->checksum != checksum)
! 	    inform ("checksum is %x instead of %x", entry->checksum, checksum);
! 	  else
! 	    inform ("number of counters is %d instead of %d",
! 		    entry->summary.num, expected);
! 	}
! 
!       if (warn_coverage_mismatch
! 	  && !inhibit_warnings
! 	  && !warned++)
! 	{
! 	  inform ("coverage mismatch ignored due to -Wcoverage-mismatch");
! 	  inform (flag_guess_branch_prob
! 		  ? "execution counts estimated"
! 		  : "execution counts assumed to be zero");
! 	  if (!flag_guess_branch_prob)
! 	    inform ("this can result in poorly optimized code");
! 	}
! 
!       return NULL;
      }
  
    if (summary)
Index: gcc/doc/invoke.texi
===================================================================
*** gcc.orig/doc/invoke.texi	2007-01-22 11:02:01.000000000 +0100
--- gcc/doc/invoke.texi	2007-01-22 11:09:53.000000000 +0100
*************** Objective-C and Objective-C++ Dialects}.
*** 225,231 ****
  -w  -Wextra  -Wall  -Waggregate-return -Walways-true -Warray-bounds @gol
  -Wno-attributes -Wc++-compat -Wcast-align  -Wcast-qual  -Wchar-subscripts @gol
  -Wclobbered  -Wcomment @gol
! -Wconversion  -Wno-deprecated-declarations @gol
  -Wdisabled-optimization  -Wno-div-by-zero  @gol
  -Wempty-body  -Wno-endif-labels @gol
  -Werror  -Werror-* -Werror-implicit-function-declaration @gol
--- 225,231 ----
  -w  -Wextra  -Wall  -Waggregate-return -Walways-true -Warray-bounds @gol
  -Wno-attributes -Wc++-compat -Wcast-align  -Wcast-qual  -Wchar-subscripts @gol
  -Wclobbered  -Wcomment @gol
! -Wconversion  -Wcoverage-mismatch -Wno-deprecated-declarations @gol
  -Wdisabled-optimization  -Wno-div-by-zero  @gol
  -Wempty-body  -Wno-endif-labels @gol
  -Werror  -Werror-* -Werror-implicit-function-declaration @gol
*************** diagnostic emitted, which indicates whic
*** 2282,2287 ****
--- 2282,2301 ----
  controls that diagnostic, when such an option is known to the
  diagnostic machinery.
  
+ @item -Wcoverage-mismatch
+ @opindex Wcoverage-mismatch
+ Warn if feedback profiles do not match when using the
+ @option{-fprofile-use} option.
+ If a source file was changed between @option{-fprofile-gen} and
+ @option{-fprofile-use}, the files with the profile feedback can fail
+ to match the source file and GCC can not use the profile feedback
+ information.  By default, GCC emits an error message in this case.
+ The option @option{-Wcoverage-mismatch} emits a warning instead of an
+ error.  GCC does not use appropriate feedback profiles, so using this
+ option can result in poorly optimized code.  This option is useful
+ only in the case of very minor changes such as bugfixes to an
+ existing code-base.
+ 
  @end table
  
  @node Warning Options
*************** generally profitable only with profile f
*** 5608,5613 ****
--- 5622,5631 ----
  The following options are enabled: @code{-fbranch-probabilities}, @code{-fvpt},
  @code{-funroll-loops}, @code{-fpeel-loops}, @code{-ftracer}
  
+ 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.
  @end table
  
  The following options control compiler behavior regarding floating
Index: gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
===================================================================
*** gcc.orig/testsuite/gcc.dg/tree-prof/tree-prof.exp	2006-02-07 11:14:07.000000000 +0100
--- gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp	2007-01-22 13:46:33.000000000 +0100
*************** load_lib profopt.exp
*** 41,48 ****
  # These are globals used by profopt-execute.  The first is options
  # needed to generate profile data, the second is options to use the
  # profile data.
! set profile_option "-fprofile-generate"
! set feedback_option "-fprofile-use"
  
  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
      # If we're only testing specific files and this isn't one of them, skip it.
--- 41,48 ----
  # These are globals used by profopt-execute.  The first is options
  # needed to generate profile data, the second is options to use the
  # profile data.
! set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
! set feedback_option "-fprofile-use -D_PROFILE_USE"
  
  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
      # If we're only testing specific files and this isn't one of them, skip it.
Index: gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch-1.c
===================================================================
*** /dev/null	1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch-1.c	2007-01-22 14:48:13.000000000 +0100
***************
*** 0 ****
--- 1,23 ----
+ /* { dg-options "-O2" } */
+ 
+ int __attribute__((noinline)) bar (void)
+ {
+ }
+ 
+ int foo (int i)
+ {
+ #ifdef _PROFILE_USE
+   if (i)
+     bar ();
+ #endif
+   return 0;
+ }
+ 
+ int main(int argc, char **argv)
+ {
+   foo (argc);
+   return 0;
+ }
+ 
+ /* xfail this somehow, or expect "coverage mismatch" error, but only
+    for the -fprofile-use compile.  */
Index: gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch-2.c
===================================================================
*** /dev/null	1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch-2.c	2007-01-22 14:39:52.000000000 +0100
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-options "-O2 -Wcoverage-mismatch -w" } */
+ 
+ int __attribute__((noinline)) bar (void)
+ {
+ }
+ 
+ int foo (int i)
+ {
+ #ifdef _PROFILE_USE
+   if (i)
+     bar ();
+ #endif
+   return 0;
+ }
+ 
+ int main(int argc, char **argv)
+ {
+   foo (argc);
+   return 0;
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]