From patchwork Sun Aug 3 14:49:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 376062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7127F1400A3 for ; Mon, 4 Aug 2014 00:49:33 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=JPldSHLbp7Kj7JbYVN2Ajqhl33wE9TpvkQC23OGefZUOVzpJG55aY UpzWfh1z9Xoswx2fuL2UgkAN+QsTqEDbgrDRr8uKszzDaCtDTAf4c2mbKUl3U5kZ s7nxGayvIZfJokRNf/mpmEUTL7R1zozMBZzCg62hpS2KTFO8PNxThM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=7xv5xg6jPpN4XMls7VVMRX2mStc=; b=cO7eFDQ5zrYmeIIyMgOg /DS2YC+B7fqclPC8B0cYk5meqlaIduo8kG1nSwp6yfxMEV1HJkz4q7U3Vc5wuKZJ iAXzTlJvlh16lSK5o9epBp/e6/N0THdDiQRwk/Kjda5RjuqMj5w5A8ryZRWC3rkA RM7ftR0cKybu+32I3y9oHtQ= Received: (qmail 2788 invoked by alias); 3 Aug 2014 14:49:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2761 invoked by uid 89); 3 Aug 2014 14:49:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 03 Aug 2014 14:49:22 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2AE32542C92; Sun, 3 Aug 2014 16:49:18 +0200 (CEST) Date: Sun, 3 Aug 2014 16:49:18 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, tsaunders@mozilla.com Subject: [RFA] Introdue warning_n; fix singulars in the final keyword wanrings Message-ID: <20140803144918.GB3695@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) * diagnostic.c (warning_n): New function. * diagnostic-core.h (warning_n): Declare. * ipa-devirt.c (ipa_devirt): Handle singulars correctly; output dynamic counts when available. Index: diagnostic.c =================================================================== --- diagnostic.c (revision 213526) +++ diagnostic.c (working copy) @@ -986,6 +986,28 @@ warning_at (location_t location, int opt return ret; } +/* A warning at LOCATION. Use this for code which is correct according to the + relevant language specification but is likely to be buggy anyway. + Returns true if the warning was printed, false if it was inhibited. */ + +bool +warning_n (location_t location, int opt, int n, const char *singular_gmsgid, + const char *plural_gmsgid, ...) +{ + diagnostic_info diagnostic; + va_list ap; + bool ret; + + va_start (ap, plural_gmsgid); + diagnostic_set_info_translated (&diagnostic, + ngettext (singular_gmsgid, plural_gmsgid, n), + &ap, location, DK_WARNING); + diagnostic.option_index = opt; + ret = report_diagnostic (&diagnostic); + va_end (ap); + return ret; +} + /* A "pedantic" warning at LOCATION: issues a warning unless -pedantic-errors was given on the command line, in which case it issues an error. Use this for diagnostics required by the relevant Index: diagnostic-core.h =================================================================== --- diagnostic-core.h (revision 213526) +++ diagnostic-core.h (working copy) @@ -58,6 +58,8 @@ extern void internal_error (const char * ATTRIBUTE_NORETURN; /* Pass one of the OPT_W* from options.h as the first parameter. */ extern bool warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); +extern bool warning_n (location_t, int, int, const char *, const char *, ...) + ATTRIBUTE_GCC_DIAG(4,6) ATTRIBUTE_GCC_DIAG(5,6); extern bool warning_at (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); Index: ipa-devirt.c =================================================================== --- ipa-devirt.c (revision 213526) +++ ipa-devirt.c (working copy) @@ -3279,12 +3279,31 @@ ipa_devirt (void) if (final_warning_records->type_warnings[i].count) { tree type = final_warning_records->type_warnings[i].type; - warning_at (DECL_SOURCE_LOCATION (TYPE_NAME (type)), - OPT_Wsuggest_final_types, - "Declaring type %qD final " - "would enable devirtualization of %i calls", - type, - final_warning_records->type_warnings[i].count); + int count = final_warning_records->type_warnings[i].count; + long long dyn_count + = final_warning_records->type_warnings[i].dyn_count; + + if (!dyn_count) + warning_n (DECL_SOURCE_LOCATION (TYPE_NAME (type)), + OPT_Wsuggest_final_types, count, + "Declaring type %qD final " + "would enable devirtualization of %i call", + "Declaring type %qD final " + "would enable devirtualization of %i calls", + type, + count); + else + warning_n (DECL_SOURCE_LOCATION (TYPE_NAME (type)), + OPT_Wsuggest_final_types, count, + "Declaring type %qD final " + "would enable devirtualization of %i call " + "executed %lli times", + "Declaring type %qD final " + "would enable devirtualization of %i calls " + "executed %lli times", + type, + count, + dyn_count); } } @@ -3299,19 +3318,45 @@ ipa_devirt (void) { tree decl = decl_warnings_vec[i]->decl; int count = decl_warnings_vec[i]->count; + long long dyn_count = decl_warnings_vec[i]->dyn_count; - if (DECL_CXX_DESTRUCTOR_P (decl)) - warning_at (DECL_SOURCE_LOCATION (decl), - OPT_Wsuggest_final_methods, - "Declaring virtual destructor of %qD final " - "would enable devirtualization of %i calls", - DECL_CONTEXT (decl), count); - else - warning_at (DECL_SOURCE_LOCATION (decl), - OPT_Wsuggest_final_methods, - "Declaring method %qD final " - "would enable devirtualization of %i calls", - decl, count); + if (!dyn_count) + if (DECL_CXX_DESTRUCTOR_P (decl)) + warning_n (DECL_SOURCE_LOCATION (decl), + OPT_Wsuggest_final_methods, count, + "Declaring virtual destructor of %qD final " + "would enable devirtualization of %i call", + "Declaring virtual destructor of %qD final " + "would enable devirtualization of %i calls", + DECL_CONTEXT (decl), count); + else + warning_n (DECL_SOURCE_LOCATION (decl), + OPT_Wsuggest_final_methods, count, + "Declaring method %qD final " + "would enable devirtualization of %i call", + "Declaring method %qD final " + "would enable devirtualization of %i calls", + decl, count); + else if (DECL_CXX_DESTRUCTOR_P (decl)) + warning_n (DECL_SOURCE_LOCATION (decl), + OPT_Wsuggest_final_methods, count, + "Declaring virtual destructor of %qD final " + "would enable devirtualization of %i call " + "executed %lli times", + "Declaring virtual destructor of %qD final " + "would enable devirtualization of %i calls " + "executed %lli times", + DECL_CONTEXT (decl), count, dyn_count); + else + warning_n (DECL_SOURCE_LOCATION (decl), + OPT_Wsuggest_final_methods, count, + "Declaring method %qD final " + "would enable devirtualization of %i call " + "executed %lli times", + "Declaring method %qD final " + "would enable devirtualization of %i calls " + "executed %lli times", + decl, count, dyn_count); } }