From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11151 invoked by alias); 21 Mar 2013 12:52:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 11122 invoked by uid 89); 21 Mar 2013 12:52:51 -0000 X-Spam-SWARE-Status: No, score=-8.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 21 Mar 2013 12:52:45 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2LCqfd5004590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Mar 2013 08:52:41 -0400 Received: from zalov.cz (vpn-55-62.rdu2.redhat.com [10.10.55.62]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2LCqd38027846 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 21 Mar 2013 08:52:40 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r2LCqbbL017657; Thu, 21 Mar 2013 13:52:38 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r2LCqaZT017656; Thu, 21 Mar 2013 13:52:36 +0100 Date: Thu, 21 Mar 2013 12:52:00 -0000 From: Jakub Jelinek To: Gabriel Dos Reis Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Count -Werror promoted warnings separately (PR middle-end/48087) Message-ID: <20130321125235.GS12913@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2013-03/txt/msg00800.txt.bz2 Hi! This is a patch I had written two months ago, but concluded it to be too risky for 4.8 at that point. The issue this patch attempts to solve is that compiler behaves differently in some cases depending on if we've just warned about something or if -Werror has been in effect and that warning has been promoted to error. Of course the difference should be the exit code from the compiler and the wording of the warning resp. error, but various bits of code e.g. in the frontends check whether any errors have been reported already (or reported while parsing some construct etc.), and if they have been, act differently from the case when there haven't been any errors. The patch just counts the warnings promoted to errors in a different counter, werrorcount, and thus each place can actually decide if it wants to treat warnings promoted to errors as warnings, or as errors, or something else for its purposes. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-03-21 Jakub Jelinek PR middle-end/48087 * diagnostic.def (DK_WERROR): New kind. * diagnostic.h (werrorcount): Define. * diagnostic.c (diagnostic_report_diagnostic): For DK_WARNING promoted to DK_ERROR, increment DK_WERROR counter instead of DK_ERROR counter. * toplev.c (toplev_main): Call print_ignored_options even if just werrorcount is non-zero. Exit with FATAL_EXIT_CODE even if just werrorcount is non-zero. * pt.c (convert_nontype_argument): Count werrorcount as warnings. * call.c (build_temp): Likewise. * method.c (synthesize_method): Likewise. * typeck.c (convert_for_initialization): Likewise. --- gcc/diagnostic.def.jj 2013-01-11 09:02:25.000000000 +0100 +++ gcc/diagnostic.def 2013-01-15 15:28:06.234384990 +0100 @@ -42,4 +42,6 @@ DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug prefix does not matter. */ DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ") DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ") - +/* This one is just for counting DK_WARNING promoted to DK_ERROR + due to -Werror and -Werror=warning. */ +DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ") --- gcc/diagnostic.h.jj 2013-01-11 09:02:35.000000000 +0100 +++ gcc/diagnostic.h 2013-01-15 15:28:42.322166705 +0100 @@ -240,6 +240,8 @@ extern diagnostic_context *global_dc; #define errorcount diagnostic_kind_count (global_dc, DK_ERROR) /* Similarly, but for warnings. */ #define warningcount diagnostic_kind_count (global_dc, DK_WARNING) +/* Similarly, but for warnings promoted to errors. */ +#define werrorcount diagnostic_kind_count (global_dc, DK_WERROR) /* Similarly, but for sorrys. */ #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) --- gcc/diagnostic.c.jj 2013-01-11 09:02:35.000000000 +0100 +++ gcc/diagnostic.c 2013-01-15 15:30:47.848421565 +0100 @@ -729,7 +729,10 @@ diagnostic_report_diagnostic (diagnostic diagnostic->message.format_spec, diagnostic->message.args_ptr); } - ++diagnostic_kind_count (context, diagnostic->kind); + if (diagnostic->kind == DK_ERROR && orig_diag_kind == DK_WARNING) + ++diagnostic_kind_count (context, DK_WERROR); + else + ++diagnostic_kind_count (context, diagnostic->kind); saved_format_spec = diagnostic->message.format_spec; if (context->show_option_requested) --- gcc/toplev.c.jj 2013-01-11 09:02:37.000000000 +0100 +++ gcc/toplev.c 2013-01-15 15:31:37.916124287 +0100 @@ -1951,7 +1951,7 @@ toplev_main (int argc, char **argv) if (!exit_after_options) do_compile (); - if (warningcount || errorcount) + if (warningcount || errorcount || werrorcount) print_ignored_options (); diagnostic_finish (global_dc); @@ -1960,7 +1960,7 @@ toplev_main (int argc, char **argv) finalize_plugins (); location_adhoc_data_fini (line_table); - if (seen_error ()) + if (seen_error () || werrorcount) return (FATAL_EXIT_CODE); return (SUCCESS_EXIT_CODE); --- gcc/cp/pt.c.jj 2013-01-15 10:29:23.000000000 +0100 +++ gcc/cp/pt.c 2013-01-15 15:35:21.912792746 +0100 @@ -5597,12 +5597,12 @@ convert_nontype_argument (tree type, tre { if (complain & tf_error) { - int errs = errorcount, warns = warningcount; + int errs = errorcount, warns = warningcount + werrorcount; if (processing_template_decl && !require_potential_constant_expression (expr)) return NULL_TREE; expr = cxx_constant_value (expr); - if (errorcount > errs || warningcount > warns) + if (errorcount > errs || warningcount + werrorcount > warns) inform (EXPR_LOC_OR_HERE (expr), "in template argument for type %qT ", type); if (expr == error_mark_node) --- gcc/cp/call.c.jj 2013-01-11 09:02:46.000000000 +0100 +++ gcc/cp/call.c 2013-01-15 15:34:21.267155075 +0100 @@ -5709,12 +5709,12 @@ build_temp (tree expr, tree type, int fl int savew, savee; vec *args; - savew = warningcount, savee = errorcount; + savew = warningcount + werrorcount, savee = errorcount; args = make_tree_vector_single (expr); expr = build_special_member_call (NULL_TREE, complete_ctor_identifier, &args, type, flags, complain); release_tree_vector (args); - if (warningcount > savew) + if (warningcount + werrorcount > savew) *diagnostic_kind = DK_WARNING; else if (errorcount > savee) *diagnostic_kind = DK_ERROR; --- gcc/cp/method.c.jj 2013-01-11 09:02:46.000000000 +0100 +++ gcc/cp/method.c 2013-01-15 15:38:45.846615219 +0100 @@ -750,7 +750,7 @@ synthesize_method (tree fndecl) tree stmt; location_t save_input_location = input_location; int error_count = errorcount; - int warning_count = warningcount; + int warning_count = warningcount + werrorcount; /* Reset the source location, we might have been previously deferred, and thus have saved where we were first needed. */ @@ -812,7 +812,7 @@ synthesize_method (tree fndecl) pop_deferring_access_checks (); - if (error_count != errorcount || warning_count != warningcount) + if (error_count != errorcount || warning_count != warningcount + werrorcount) inform (input_location, "synthesized method %qD first required here ", fndecl); } --- gcc/cp/typeck.c.jj 2013-01-11 09:02:46.000000000 +0100 +++ gcc/cp/typeck.c 2013-01-15 15:35:47.216641020 +0100 @@ -7967,11 +7967,11 @@ convert_for_initialization (tree exp, tr int savew = 0, savee = 0; if (fndecl) - savew = warningcount, savee = errorcount; + savew = warningcount + werrorcount, savee = errorcount; rhs = initialize_reference (type, rhs, flags, complain); if (fndecl) { - if (warningcount > savew) + if (warningcount + werrorcount > savew) warning (0, "in passing argument %P of %q+D", parmnum, fndecl); else if (errorcount > savee) error ("in passing argument %P of %q+D", parmnum, fndecl); Jakub