From patchwork Fri May 5 21:29:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 759190 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 3wKPNw1Xd0z9s7j for ; Sat, 6 May 2017 06:57:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kpXDAZVK"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=Gbw9qtFkE/l6 jUNv7n7fHjIiiC3YgRsfaLocxHvrJUdAOr5R0dAXbWrhfrdey9WuY+I2z3pIaqSO Is8USNH+vjairFM80wki2e6ndmskQqg0jgZjwz2cX/lrlqbBeq7gWi+cwLEmcfng zZ3hzqsZvkJlB1frY5j0Qntv3ofDYjg= 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:from :to:cc:subject:date:message-id; s=default; bh=7703ILiJ9ipe/4dc6g aUvHKnSOQ=; b=kpXDAZVKYCyaD9SqweVPIy2+JvNIvIh0H4cfTW0vDjNk5kV9V5 U+/prV1FckKFPGFQLIU4KloL7ZsJlSymFstRa+rr7kW0YrekbTjre4rMjajRGQji y+WgOIjsRxjnNIcYwt7AGtXhWZbIhVwDDCXTIp96BrY4CCvh2VzEgyb0w= Received: (qmail 40071 invoked by alias); 5 May 2017 20:57:38 -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 40060 invoked by uid 89); 5 May 2017 20:57:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 05 May 2017 20:57:36 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84B9480489 for ; Fri, 5 May 2017 20:57:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 84B9480489 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dmalcolm@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 84B9480489 Received: from c64.redhat.com (ovpn-112-30.phx2.redhat.com [10.3.112.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD6767A430; Fri, 5 May 2017 20:57:36 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] diagnostic.c: add print_option_information Date: Fri, 5 May 2017 17:29:01 -0400 Message-Id: <1494019741-23863-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes This patch simplifies diagnostic_report_diagnostic by moving option-printing to a new subroutine. Doing so required a slight rewrite. In both the old and new code, context->option_name returns a malloc-ed string. The old behavior was to then use ACONCAT to manipulate the format_spec, appending the option metadata. ACONCAT calcs the buffer size, then uses alloca, and then copies the data to the on-stack buffer. Given the alloca, this needs rewriting when moving the printing to a subroutine. In the new version, the metadata is simply printed using pp_* calls (so it's hitting the obstack within the pretty_printer). This means we can get rid of the save/restore of format_spec: I don't believe anything else in the code modifies it. It also seems inherently simpler; it seems odd to me to be appending metadata to the formatting string, rather than simply printing the metadata after the formatted string is printed (the old code also assumed that no option name contained a '%'). No functional change intended. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. Committed to trunk as r247661. gcc/ChangeLog: * diagnostic.c (diagnostic_report_diagnostic): Eliminate save/restor of format_spec. Move option-printing code to... (print_option_information): ...this new function, and reimplement by simply printing to the pretty_printer, rather than appending to the format string. --- gcc/diagnostic.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index b61c09e..f1b6b1e 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -815,6 +815,32 @@ update_effective_level_from_pragmas (diagnostic_context *context, return diag_class; } +/* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's + printer, e.g. " [-Werror=uninitialized]". + Subroutine of diagnostic_report_diagnostic. */ + +static void +print_option_information (diagnostic_context *context, + const diagnostic_info *diagnostic, + diagnostic_t orig_diag_kind) +{ + char *option_text; + + option_text = context->option_name (context, diagnostic->option_index, + orig_diag_kind, diagnostic->kind); + + if (option_text) + { + pretty_printer *pp = context->printer; + pp_string (pp, " ["); + pp_string (pp, colorize_start (pp_show_color (pp), + diagnostic_kind_color[diagnostic->kind])); + pp_string (pp, option_text); + pp_string (pp, colorize_stop (pp_show_color (pp))); + pp_character (pp, ']'); + free (option_text); + } +} /* Report a diagnostic message (an error or a warning) as specified by DC. This function is *the* subroutine in terms of which front-ends @@ -829,7 +855,6 @@ diagnostic_report_diagnostic (diagnostic_context *context, { location_t location = diagnostic_location (diagnostic); diagnostic_t orig_diag_kind = diagnostic->kind; - const char *saved_format_spec; /* Give preference to being able to inhibit warnings, before they get reclassified to something else. */ @@ -925,33 +950,13 @@ diagnostic_report_diagnostic (diagnostic_context *context, else ++diagnostic_kind_count (context, diagnostic->kind); - saved_format_spec = diagnostic->message.format_spec; - if (context->show_option_requested) - { - char *option_text; - - option_text = context->option_name (context, diagnostic->option_index, - orig_diag_kind, diagnostic->kind); - - if (option_text) - { - const char *cs - = colorize_start (pp_show_color (context->printer), - diagnostic_kind_color[diagnostic->kind]); - const char *ce = colorize_stop (pp_show_color (context->printer)); - diagnostic->message.format_spec - = ACONCAT ((diagnostic->message.format_spec, - " ", - "[", cs, option_text, ce, "]", - NULL)); - free (option_text); - } - } diagnostic->message.x_data = &diagnostic->x_data; diagnostic->x_data = NULL; pp_format (context->printer, &diagnostic->message); (*diagnostic_starter (context)) (context, diagnostic); pp_output_formatted_text (context->printer); + if (context->show_option_requested) + print_option_information (context, diagnostic, orig_diag_kind); (*diagnostic_finalizer (context)) (context, diagnostic); if (context->parseable_fixits_p) { @@ -959,7 +964,6 @@ diagnostic_report_diagnostic (diagnostic_context *context, pp_flush (context->printer); } diagnostic_action_after_output (context, diagnostic->kind); - diagnostic->message.format_spec = saved_format_spec; diagnostic->x_data = NULL; if (context->edit_context_ptr)