From: Neil Vachharajani Date: Tue, 4 May 2010 23:45:58 +0000 (+0000) Subject: Sanitize the behavior of -Wcoverage-mismatch. X-Git-Tag: upstream/12.2.0~93347 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=650cfcab96c03bae93fe5eceafce792e86a661e3;p=platform%2Fupstream%2Fgcc.git Sanitize the behavior of -Wcoverage-mismatch. 2010-05-04 Neil Vachharajani * doc/invoke.texi (-Wcoverage-mismatch): Updated documentation as per new semantics. * opts.c (decode_options): Enable -Werror=coverage-mismatch. * coverage.c (get_coverage_counts): Always emit a warning. Adjust conditions for printing notes. * common.opt (-Wcoverage-mismatch): Allow negative, default to true, update documentation. * Makefile.in (coverage.o): Add dependence on DIAGNOSTIC_H and intl.h. * testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c: Adjusted. From-SVN: r159050 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 21f145e9..5eed15d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2010-05-04 Neil Vachharajani + + * doc/invoke.texi (-Wcoverage-mismatch): Updated documentation as + per new semantics. + * opts.c (decode_options): Enable -Werror=coverage-mismatch. + * coverage.c (get_coverage_counts): Always emit a warning. Adjust + conditions for printing notes. + * common.opt (-Wcoverage-mismatch): Allow negative, default to + true, update documentation. + * Makefile.in (coverage.o): Add dependence on DIAGNOSTIC_H and intl.h. + * testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c: Adjusted. + 2010-05-04 Jakub Jelinek PR c/43981 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 6da2c97..7c42b7c 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2947,7 +2947,8 @@ ipa-struct-reorg.o: ipa-struct-reorg.c ipa-struct-reorg.h $(CONFIG_H) $(SYSTEM_H coverage.o : coverage.c $(GCOV_IO_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(RTL_H) $(TREE_H) $(FLAGS_H) output.h $(REGS_H) $(EXPR_H) \ $(FUNCTION_H) $(TOPLEV_H) $(GGC_H) langhooks.h $(COVERAGE_H) gt-coverage.h \ - $(HASHTAB_H) tree-iterator.h $(CGRAPH_H) $(TREE_PASS_H) gcov-io.c $(TM_P_H) + $(HASHTAB_H) tree-iterator.h $(CGRAPH_H) $(TREE_PASS_H) gcov-io.c $(TM_P_H) \ + $(DIAGNOSTIC_H) intl.h cselib.o : cselib.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(REGS_H) hard-reg-set.h $(FLAGS_H) $(REAL_H) insn-config.h $(RECOG_H) \ $(EMIT_RTL_H) $(TOPLEV_H) output.h $(FUNCTION_H) $(TREE_PASS_H) \ diff --git a/gcc/common.opt b/gcc/common.opt index e62e3d5..806bd1f 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -249,8 +249,8 @@ Common Var(warn_unused_variable) Init(-1) Warning Warn when a variable is unused Wcoverage-mismatch -Common RejectNegative Var(warn_coverage_mismatch) Warning -Warn instead of error in case profiles in -fprofile-use do not match +Common Var(warn_coverage_mismatch) Init(1) Warning +Warn in case profiles in -fprofile-use do not match aux-info Common Separate diff --git a/gcc/coverage.c b/gcc/coverage.c index e04d22b..addfac9 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -46,6 +46,8 @@ along with GCC; see the file COPYING3. If not see #include "tree-iterator.h" #include "cgraph.h" #include "tree-pass.h" +#include "diagnostic.h" +#include "intl.h" #include "gcov-io.c" @@ -357,34 +359,33 @@ get_coverage_counts (unsigned counter, unsigned expected, || entry->summary.num != expected) { static int warned = 0; + bool warning_printed = false; tree id = DECL_ASSEMBLER_NAME (current_function_decl); - if (warn_coverage_mismatch) - warning (OPT_Wcoverage_mismatch, "coverage mismatch for function " - "%qE while reading counter %qs", id, ctr_names[counter]); - else - error ("coverage mismatch for function %qE while reading counter %qs", - id, ctr_names[counter]); - - if (!inhibit_warnings) + warning_printed = + warning_at (input_location, OPT_Wcoverage_mismatch, + "coverage mismatch for function " + "%qE while reading counter %qs", id, ctr_names[counter]); + if (warning_printed) { if (entry->checksum != checksum) - inform (input_location, "checksum is %x instead of %x", entry->checksum, checksum); + inform (input_location, "checksum is %x instead of %x", + entry->checksum, checksum); else inform (input_location, "number of counters is %d instead of %d", entry->summary.num, expected); - } - - if (warn_coverage_mismatch - && !inhibit_warnings - && !warned++) - { - inform (input_location, "coverage mismatch ignored due to -Wcoverage-mismatch"); - inform (input_location, flag_guess_branch_prob - ? "execution counts estimated" - : "execution counts assumed to be zero"); - if (!flag_guess_branch_prob) - inform (input_location, "this can result in poorly optimized code"); + + if (!(errorcount || sorrycount) + && !warned++) + { + inform (input_location, "coverage mismatch ignored"); + inform (input_location, flag_guess_branch_prob + ? G_("execution counts estimated") + : G_("execution counts assumed to be zero")); + if (!flag_guess_branch_prob) + inform (input_location, + "this can result in poorly optimized code"); + } } return NULL; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b2fbd48..237f894 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2755,12 +2755,13 @@ Warn if feedback profiles do not match when using the 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 bug fixes to an -existing code-base. +information. By default, this warning is enabled and is treated as an +error. @option{-Wno-coverage-mismatch} can be used to disable the +warning or @option{-Wno-error=coverage-mismatch} can be used to +disable the error. Disable the error for this warning can result in +poorly optimized code, so disabling the error is useful only in the +case of very minor changes such as bug fixes to an existing code-base. +Completely disabling the warning is not recommended. @end table diff --git a/gcc/opts.c b/gcc/opts.c index 507b502..fd8a504 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -946,6 +946,9 @@ decode_options (unsigned int argc, const char **argv) else set_param_value ("min-crossjump-insns", initial_min_crossjump_insns); + /* Enable -Werror=coverage-mismatch by default */ + enable_warning_as_error("coverage-mismatch", 1, lang_mask); + if (first_time_p) { /* Initialize whether `char' is signed. */ diff --git a/gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c b/gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c index 74fe7f8..e423105 100644 --- a/gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c +++ b/gcc/testsuite/gcc.dg/tree-prof/wcoverage-mismatch.c @@ -1,4 +1,4 @@ -/* { dg-options "-O2 -Wcoverage-mismatch -w" } */ +/* { dg-options "-O2 -Wno-coverage-mismatch" } */ int __attribute__((noinline)) bar (void) {