]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
invoke.texi (-Wcoverage-mismatch): Document.
authorRichard Guenther <rguenther@suse.de>
Thu, 25 Jan 2007 12:35:13 +0000 (12:35 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 25 Jan 2007 12:35:13 +0000 (12:35 +0000)
2007-01-25  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.c: New testcase.

From-SVN: r121169

gcc/ChangeLog
gcc/common.opt
gcc/coverage.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c [new file with mode: 0644]

index 8213ceec2d53dae7e34d908c2ea4f15f61375fae..2a8cde814b1d7d38617c0f2931aca36a61577545 100644 (file)
@@ -1,3 +1,10 @@
+2007-01-25  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.
+
 2007-01-25  Razya Ladelsky  <razya@il.ibm.com>
 
         * ipa-cp.c (ipcp_insert_stage, ipcp_driver): Support for SSA. 
index dfcda946aa2198f9333c79f79bdb22ac8576a4f7..0a0d287c78a8bbbcbdcd35ecc73b4e12e48c6d93 100644 (file)
@@ -197,6 +197,10 @@ Wvolatile-register-var
 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 399eb6ea6c6a861d8cdad2fb91441132504036e4..ba9f1285fc2dd60a63955453c3446de995a9e8f3 100644 (file)
@@ -347,25 +347,46 @@ get_coverage_counts (unsigned counter, unsigned expected,
     {
       warning (0, "no coverage for function %qs found", IDENTIFIER_POINTER
               (DECL_ASSEMBLER_NAME (current_function_decl)));
-      return 0;
+      return NULL;
     }
 
   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)
+  if (entry->checksum != checksum
+      || 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;
+      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 18fee96e5205b13bcd6059ff22ad72950a441109..fee5871dc89617f03e2fc9d30483be194992f2ee 100644 (file)
@@ -225,7 +225,7 @@ Objective-C and Objective-C++ Dialects}.
 -w  -Wextra  -Wall  -Waggregate-return -Walways-true -Warray-bounds @gol
 -Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align  -Wcast-qual  @gol
 -Wchar-subscripts -Wclobbered  -Wcomment @gol
--Wconversion  -Wno-deprecated-declarations @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
@@ -2282,6 +2282,20 @@ diagnostic emitted, which indicates which command line option directly
 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
@@ -5613,6 +5627,10 @@ generally profitable only with profile feedback available.
 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 6ac5d273a2504bd25016d7cb1e417fde76eb426c..a769a06195561b954672e1a795ff26845d98fc36 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-25  Richard Guenther  <rguenther@suse.de>
+
+       * gcc.dg/tree-prof/tree-prof.exp: Define _PROFILE_GENERATE
+       and _PROFILE_USE.
+       * gcc.dg/tree-prof/wcoverage-mismatch.c: New testcase.
+
 2007-01-25  Razya Ladelsky  <razya@il.ibm.com>
 
         * gcc.dg/ipa/ipa-1.c: Update scan tree dump.
index f7438194396df188177e8eed3d72ef14f886620e..70b2d4e17dd92fce21f431722d74616f7d8367cd 100644 (file)
@@ -41,8 +41,8 @@ load_lib profopt.exp
 # 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"
+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.
diff --git a/gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c b/gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c
new file mode 100644 (file)
index 0000000..74fe7f8
--- /dev/null
@@ -0,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;
+}