From patchwork Sat Nov 16 01:22:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1195994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513718-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CB2STHnV"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="jRi0Yc9N"; dkim-atps=neutral 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 47FHQ53PKWz9s7T for ; Sat, 16 Nov 2019 12:17:33 +1100 (AEDT) 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:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=JzF pCyaIgEVPkSP5dM7T+uny2dQBUL7TQ5aTLXCOC+ttybnKNcSRHKsb3DhP14VRvrL QLUhfmssJQ4ttawCQattmJ41wuQSfln0mzctG/tksjduHH7alp7U0xMZf2gzwWd7 5tEBWyAkNxe4q/N5zo6U8xQ9cMxyq/G+dukif57Y= 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:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=7G1QF8Qhk W7LT5uwfooHaW+Pasc=; b=CB2STHnV/6t6ZKhWLJefWyg0F7Y31aOy7OkF5gtnV dxjRjNT6H4TuOKIFNJpXum2i8EB48s9e0O400KbGKhpIIzRADFQ352VTng75UTPY zTTyfKG9G+49M7bgP5gngL4ML4oGSuZ9at+qOWSO1pNA7muSFVwhjck6kmLf4bDZ 1o= Received: (qmail 55222 invoked by alias); 16 Nov 2019 01:17:12 -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 55145 invoked by uid 89); 16 Nov 2019 01:17:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=LONGER, kit, 1853, c_dialect_cxx X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 16 Nov 2019 01:17:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573867026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ropa9KXe9E225vP8Vq190y103MnIeVWZAWhU4F2Sv34=; b=jRi0Yc9NDcg/WuqGCONWWwz3pWHUSBvMBHOI3qefCFz3Em8oPSB3YpAjd0bvI68aDPcnH0 aKxhn9+gpdbKNC+h326aPkei6MB3tH/Qu7Kr/6WKSsDgpORMLPbaw6BK9D6F0WN4hxxqb3 znJkLk8ROoKTp+vkcvJxzXbjpU2Ie50= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-_c2dBJ6-O8qzOlLt0k7amQ-1; Fri, 15 Nov 2019 20:17:04 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DCAE18B9FC1 for ; Sat, 16 Nov 2019 01:17:04 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-32.phx2.redhat.com [10.3.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06C5E10246FB; Sat, 16 Nov 2019 01:17:02 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 03/49] diagnostic_show_locus: move initial newline to callers Date: Fri, 15 Nov 2019 20:22:50 -0500 Message-Id: <1573867416-55618-4-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1573867416-55618-1-git-send-email-dmalcolm@redhat.com> References: <1573867416-55618-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes diagnostic_show_locus adds a newline before doing anything (including the do-nothing-else case). This patch removes this initial newline, adding it to all callers of diagnostic_show_locus instead. Doing so makes diagnostic_show_locus more flexible, allowing it to be used later in this patch kit when printing diagnostic paths. gcc/c-family/ChangeLog: * c-format.c (test_type_mismatch_range_labels): Remove initial newline from expected outputs. * c-opts.c (c_diagnostic_finalizer): Add pp_newline call before call to diagnostic_show_locus. gcc/ChangeLog: * diagnostic-show-locus.c (diagnostic_show_locus): Remove initial newline. (selftest::test_diagnostic_show_locus_unknown_location): Remove initial newline from expected output. (selftest::test_one_liner_simple_caret): Likewise. (selftest::test_one_liner_caret_and_range): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges): Likewise. (selftest::test_one_liner_fixit_insert_before): Likewise. (selftest::test_one_liner_fixit_insert_after): Likewise. (selftest::test_one_liner_fixit_remove): Likewise. (selftest::test_one_liner_fixit_replace): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations): Likewise. (selftest::test_one_liner_many_fixits_1): Likewise. (selftest::test_one_liner_many_fixits_2): Likewise. (selftest::test_one_liner_labels): Likewise. (selftest::test_add_location_if_nearby): Likewise. (selftest::test_diagnostic_show_locus_fixit_lines): Likewise. (selftest::test_overlapped_fixit_printing): Likewise. (selftest::test_overlapped_fixit_printing_2): Likewise. (selftest::test_fixit_insert_containing_newline): Likewise. (selftest::test_fixit_insert_containing_newline_2): Likewise. (selftest::test_fixit_replace_containing_newline): Likewise. (selftest::test_fixit_deletion_affecting_newline): Likewise. (selftest::test_line_numbers_multiline_range): Likewise. * diagnostic.c (default_diagnostic_finalizer): Add pp_newline call before call to diagnostic_show_locus. (diagnostic_append_note): Likewise. gcc/fortran/ChangeLog: * error.c (gfc_diagnostic_starter): Add pp_newline call before call to diagnostic_show_locus. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (custom_diagnostic_finalizer): Add pp_newline call before call to diagnostic_show_locus. --- gcc/c-family/c-format.c | 6 +- gcc/c-family/c-opts.c | 1 + gcc/diagnostic-show-locus.c | 142 +++++++-------------- gcc/diagnostic.c | 2 + gcc/fortran/error.c | 1 + .../plugin/diagnostic_plugin_test_show_locus.c | 1 + 6 files changed, 54 insertions(+), 99 deletions(-) diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 3c291ca..7ddf064 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -5390,16 +5390,14 @@ test_type_mismatch_range_labels () diagnostic_show_locus (&dc, &richloc, DK_ERROR); if (c_dialect_cxx ()) /* "char*", without a space. */ - ASSERT_STREQ ("\n" - " printf (\"msg: %i\\n\", msg);\n" + ASSERT_STREQ (" printf (\"msg: %i\\n\", msg);\n" " ~^ ~~~\n" " | |\n" " char* int\n", pp_formatted_text (dc.printer)); else /* "char *", with a space. */ - ASSERT_STREQ ("\n" - " printf (\"msg: %i\\n\", msg);\n" + ASSERT_STREQ (" printf (\"msg: %i\\n\", msg);\n" " ~^ ~~~\n" " | |\n" " | int\n" diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 0fffe60..d752328 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -170,6 +170,7 @@ c_diagnostic_finalizer (diagnostic_context *context, { char *saved_prefix = pp_take_prefix (context->printer); pp_set_prefix (context->printer, NULL); + pp_newline (context->printer); diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind); /* By default print macro expansion contexts in the diagnostic finalizer -- for tokens resulting from macro expansion. */ diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c index cb920f6..412b0d4 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -2283,8 +2283,6 @@ diagnostic_show_locus (diagnostic_context * context, rich_location *richloc, diagnostic_t diagnostic_kind) { - pp_newline (context->printer); - location_t loc = richloc->get_loc (); /* Do nothing if source-printing has been disabled. */ if (!context->show_caret) @@ -2347,7 +2345,7 @@ test_diagnostic_show_locus_unknown_location () test_diagnostic_context dc; rich_location richloc (line_table, UNKNOWN_LOCATION); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n", pp_formatted_text (dc.printer)); + ASSERT_STREQ ("", pp_formatted_text (dc.printer)); } /* Verify that diagnostic_show_locus works sanely for various @@ -2369,8 +2367,7 @@ test_one_liner_simple_caret () location_t caret = linemap_position_for_column (line_table, 10); rich_location richloc (line_table, caret); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^\n", pp_formatted_text (dc.printer)); } @@ -2387,8 +2384,7 @@ test_one_liner_caret_and_range () location_t loc = make_location (caret, start, finish); rich_location richloc (line_table, loc); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ~~~^~~~~~\n", pp_formatted_text (dc.printer)); } @@ -2421,8 +2417,7 @@ test_one_liner_multiple_carets_and_ranges () richloc.add_range (bar, SHOW_RANGE_WITH_CARET); richloc.add_range (field, SHOW_RANGE_WITH_CARET); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ~A~ ~B~ ~~C~~\n", pp_formatted_text (dc.printer)); } @@ -2437,8 +2432,7 @@ test_one_liner_fixit_insert_before () rich_location richloc (line_table, caret); richloc.add_fixit_insert_before ("&"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^\n" " &\n", pp_formatted_text (dc.printer)); @@ -2456,8 +2450,7 @@ test_one_liner_fixit_insert_after () rich_location richloc (line_table, foo); richloc.add_fixit_insert_after ("[0]"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~\n" " [0]\n", pp_formatted_text (dc.printer)); @@ -2480,8 +2473,7 @@ test_one_liner_fixit_remove () { test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~~~~\n" " ------\n", pp_formatted_text (dc.printer)); @@ -2493,8 +2485,7 @@ test_one_liner_fixit_remove () pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE; pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:")); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - "TEST PREFIX: foo = bar.field;\n" + ASSERT_STREQ ("TEST PREFIX: foo = bar.field;\n" "TEST PREFIX: ^~~~~~\n" "TEST PREFIX: ------\n", pp_formatted_text (dc.printer)); @@ -2506,8 +2497,7 @@ test_one_liner_fixit_remove () dc.show_ruler_p = true; dc.caret_max_width = 104; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " 0 0 0 0 0 0 0 0 0 1 \n" + ASSERT_STREQ (" 0 0 0 0 0 0 0 0 0 1 \n" " 1 2 3 4 5 6 7 8 9 0 \n" " 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\n" " foo = bar.field;\n" @@ -2524,8 +2514,7 @@ test_one_liner_fixit_remove () pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE; pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:")); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - "TEST PREFIX: 1 2 3 4 5\n" + ASSERT_STREQ ("TEST PREFIX: 1 2 3 4 5\n" "TEST PREFIX: 12345678901234567890123456789012345678901234567890\n" "TEST PREFIX: foo = bar.field;\n" "TEST PREFIX: ^~~~~~\n" @@ -2542,8 +2531,7 @@ test_one_liner_fixit_remove () pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE; pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:")); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - "TEST PREFIX: | 1 2 3 4 5\n" + ASSERT_STREQ ("TEST PREFIX: | 1 2 3 4 5\n" "TEST PREFIX: | 12345678901234567890123456789012345678901234567890\n" "TEST PREFIX: 1 | foo = bar.field;\n" "TEST PREFIX: | ^~~~~~\n" @@ -2564,8 +2552,7 @@ test_one_liner_fixit_replace () rich_location richloc (line_table, field); richloc.add_fixit_replace ("m_field"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~~~\n" " m_field\n", pp_formatted_text (dc.printer)); @@ -2589,8 +2576,7 @@ test_one_liner_fixit_replace_non_equal_range () diagnostic_show_locus (&dc, &richloc, DK_ERROR); /* The replacement range is not indicated in the annotation line, so it should be indicated via an additional underline. */ - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^\n" " -----\n" " m_field\n", @@ -2615,8 +2601,7 @@ test_one_liner_fixit_replace_equal_secondary_range () diagnostic_show_locus (&dc, &richloc, DK_ERROR); /* The replacement range is indicated in the annotation line, so it shouldn't be indicated via an additional underline. */ - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^ ~~~~~\n" " m_field\n", pp_formatted_text (dc.printer)); @@ -2649,8 +2634,7 @@ test_one_liner_fixit_validation_adhoc_locations () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~~~~~~~~ \n" " test\n", pp_formatted_text (dc.printer)); @@ -2666,8 +2650,7 @@ test_one_liner_fixit_validation_adhoc_locations () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~~~~~~~~ \n" " -----------------------------------------\n", pp_formatted_text (dc.printer)); @@ -2683,8 +2666,7 @@ test_one_liner_fixit_validation_adhoc_locations () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~~~~~~~~ \n" " test\n", pp_formatted_text (dc.printer)); @@ -2703,8 +2685,7 @@ test_one_liner_many_fixits_1 () richloc.add_fixit_insert_before ("a"); ASSERT_EQ (1, richloc.get_num_fixit_hints ()); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^\n" " aaaaaaaaaaaaaaaaaaa\n", pp_formatted_text (dc.printer)); @@ -2726,8 +2707,7 @@ test_one_liner_many_fixits_2 () } ASSERT_EQ (19, richloc.get_num_fixit_hints ()); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^\n" "a a a a a a a a a a a a a a a a a a a\n", pp_formatted_text (dc.printer)); @@ -2763,8 +2743,7 @@ test_one_liner_labels () { test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~ ~~~ ~~~~~\n" " | | |\n" " 0 1 2\n", @@ -2776,8 +2755,7 @@ test_one_liner_labels () test_diagnostic_context dc; dc.show_labels_p = false; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~ ~~~ ~~~~~\n", pp_formatted_text (dc.printer)); } @@ -2794,8 +2772,7 @@ test_one_liner_labels () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~ ~~~ ~~~~~\n" " | | |\n" " | | label 2\n" @@ -2816,8 +2793,7 @@ test_one_liner_labels () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~ ~~~ ~~~~~\n" " | | |\n" " | | c\n" @@ -2836,8 +2812,7 @@ test_one_liner_labels () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ~~~ ~~~ ^~~~~\n" " | | |\n" " 2 1 0\n", @@ -2856,8 +2831,7 @@ test_one_liner_labels () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~\n" " |\n" " label 0\n" @@ -2892,8 +2866,7 @@ test_one_liner_labels () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ~~~ ~~~ ^~~~~\n" " | | |\n" " | | label 0a\n" @@ -2916,8 +2889,7 @@ test_one_liner_labels () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar.field;\n" + ASSERT_STREQ (" foo = bar.field;\n" " ^~~\n", pp_formatted_text (dc.printer)); } @@ -3009,8 +2981,7 @@ test_add_location_if_nearby (const line_table_case &case_) ASSERT_EQ (2, richloc.get_num_locations ()); test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " struct same_line { double x; double y; ;\n" + ASSERT_STREQ (" struct same_line { double x; double y; ;\n" " ~ ^\n", pp_formatted_text (dc.printer)); } @@ -3074,8 +3045,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_) richloc.add_fixit_insert_before (x, "."); richloc.add_fixit_replace (colon, "="); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " struct point origin = {x: 0.0,\n" + ASSERT_STREQ (" struct point origin = {x: 0.0,\n" " ^\n" " .=\n", pp_formatted_text (dc.printer)); @@ -3095,8 +3065,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_) richloc.add_fixit_insert_before (y, "."); richloc.add_fixit_replace (colon, "="); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - "FILENAME:3:24:\n" + ASSERT_STREQ ("FILENAME:3:24:\n" " y\n" " .\n" "FILENAME:6:25:\n" @@ -3119,8 +3088,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_) test_diagnostic_context dc; dc.show_line_numbers_p = true; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " 3 | y\n" + ASSERT_STREQ (" 3 | y\n" " | .\n" "......\n" " 6 | : 0.0};\n" @@ -3330,8 +3298,7 @@ test_overlapped_fixit_printing (const line_table_case &case_) richloc.add_fixit_insert_after (")"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo *f = (foo *)ptr->field;\n" + ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n" " ^~~~~~~~~~\n" " -----------------\n" " const_cast (ptr->field)\n", @@ -3388,8 +3355,7 @@ test_overlapped_fixit_printing (const line_table_case &case_) richloc.add_fixit_insert_after (")"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo *f = (foo *)ptr->field;\n" + ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n" " ^~~~~~~~~~\n" " -\n" " CAST (-\n" @@ -3406,8 +3372,7 @@ test_overlapped_fixit_printing (const line_table_case &case_) richloc.add_fixit_insert_after (")"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo *f = (foo *)ptr->field;\n" + ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n" " ^~~~~~~~~~\n" " -\n" " CST ( -\n" @@ -3428,8 +3393,7 @@ test_overlapped_fixit_printing (const line_table_case &case_) ASSERT_EQ (1, richloc.get_num_fixit_hints ()); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo *f = (foo *)ptr->field;\n" + ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n" " ^~~~~~~~~~\n" " -------\n" " (bar *)\n", @@ -3449,8 +3413,7 @@ test_overlapped_fixit_printing (const line_table_case &case_) /* But the corrections are. */ diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo *f = (foo *)ptr->field;\n" + ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n" " ^~~~~~~~~~\n" " -----------------\n" " (longer *)(foo *)\n", @@ -3468,8 +3431,7 @@ test_overlapped_fixit_printing (const line_table_case &case_) it would overlap with the second. Verify that they are printed as a single replacement. */ diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo *f = (foo *)ptr->field;\n" + ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n" " ^~~~~~~~~~\n" " -------\n" " LONGER THAN THE CAST(foo *)TEST\n", @@ -3535,8 +3497,7 @@ test_overlapped_fixit_printing_2 (const line_table_case &case_) /* Verify that they're printed correctly. */ test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " int a5[][0][0] = { 1, 2 };\n" + ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n" " ^\n" " } {\n", pp_formatted_text (dc.printer)); @@ -3558,8 +3519,7 @@ test_overlapped_fixit_printing_2 (const line_table_case &case_) richloc.add_fixit_insert_before (col_1, "{"); richloc.add_fixit_insert_before (col_25, "}"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " int a5[][0][0] = { 1, 2 };\n" + ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n" " ^\n" " { -----\n" " {{1}}}}, {{{2 }}\n", @@ -3602,8 +3562,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_) { test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " x = a;\n" + ASSERT_STREQ (" x = a;\n" "+ break;\n" " case 'b':\n" " ^~~~~~~~~\n", @@ -3615,8 +3574,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_) test_diagnostic_context dc; dc.show_line_numbers_p = true; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " 2 | x = a;\n" + ASSERT_STREQ (" 2 | x = a;\n" " +++ |+ break;\n" " 3 | case 'b':\n" " | ^~~~~~~~~\n", @@ -3632,8 +3590,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_) ASSERT_TRUE (richloc.seen_impossible_fixit_p ()); test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " case 'b':\n" + ASSERT_STREQ (" case 'b':\n" " ^~~~~~~~~\n", pp_formatted_text (dc.printer)); } @@ -3681,8 +3638,7 @@ test_fixit_insert_containing_newline_2 (const line_table_case &case_) { test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - "FILENAME:1:1:\n" + ASSERT_STREQ ("FILENAME:1:1:\n" "+#include \n" " test (int ch)\n" "FILENAME:3:2:\n" @@ -3697,8 +3653,7 @@ test_fixit_insert_containing_newline_2 (const line_table_case &case_) test_diagnostic_context dc; dc.show_line_numbers_p = true; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " +++ |+#include \n" + ASSERT_STREQ (" +++ |+#include \n" " 1 | test (int ch)\n" " 2 | {\n" " 3 | putchar (ch);\n" @@ -3741,8 +3696,7 @@ test_fixit_replace_containing_newline (const line_table_case &case_) test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar ();\n" + ASSERT_STREQ (" foo = bar ();\n" " ^\n", pp_formatted_text (dc.printer)); } @@ -3786,8 +3740,7 @@ test_fixit_deletion_affecting_newline (const line_table_case &case_) test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " foo = bar (\n" + ASSERT_STREQ (" foo = bar (\n" " ~^\n" " );\n" " ~ \n", @@ -3830,8 +3783,7 @@ test_line_numbers_multiline_range () dc.min_margin_width = 0; gcc_rich_location richloc (loc); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " 9 | this is line 9\n" + ASSERT_STREQ (" 9 | this is line 9\n" " | ~~~~~~\n" "10 | this is line 10\n" " | ~~~~~^~~~~~~~~~\n" diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index a29bcf1..d6604e6 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -679,6 +679,7 @@ default_diagnostic_finalizer (diagnostic_context *context, { char *saved_prefix = pp_take_prefix (context->printer); pp_set_prefix (context->printer, NULL); + pp_newline (context->printer); diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind); pp_set_prefix (context->printer, saved_prefix); pp_flush (context->printer); @@ -1173,6 +1174,7 @@ diagnostic_append_note (diagnostic_context *context, pp_output_formatted_text (context->printer); pp_destroy_prefix (context->printer); pp_set_prefix (context->printer, saved_prefix); + pp_newline (context->printer); diagnostic_show_locus (context, &richloc, DK_NOTE); va_end (ap); } diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index b20aa86..03de73e 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -1147,6 +1147,7 @@ gfc_diagnostic_starter (diagnostic_context *context, /* Fortran uses an empty line between locus and caret line. */ pp_newline (context->printer); pp_set_prefix (context->printer, NULL); + pp_newline (context->printer); diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind); /* If the caret line was shown, the prefix does not contain the locus. */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c index 3f62edd..fc52de4 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c @@ -137,6 +137,7 @@ custom_diagnostic_finalizer (diagnostic_context *context, pp_show_color (context->printer) = true; char *saved_prefix = pp_take_prefix (context->printer); pp_set_prefix (context->printer, NULL); + pp_newline (context->printer); diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind); pp_show_color (context->printer) = old_show_color; pp_set_prefix (context->printer, saved_prefix);