From d3e28653fa2cd9ad8d5c6acb4bd182bd473c0995 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 10 Dec 2019 01:48:42 +0000 Subject: [PATCH] diagnostic_show_locus: move initial newline to callers 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 in my analyzer patch kit for printing diagnostic paths. gcc/c-family/ChangeLog: * c-format.c (selftest::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 outputs. (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_one_liner_simple_caret_utf8): Likewise. (selftest::test_one_liner_caret_and_range_utf8): Likewise. (selftest::test_one_liner_multiple_carets_and_ranges_utf8): Likewise. (selftest::test_one_liner_fixit_insert_before_utf8): Likewise. (selftest::test_one_liner_fixit_insert_after_utf8): Likewise. (selftest::test_one_liner_fixit_remove_utf8): Likewise. (selftest::test_one_liner_fixit_replace_utf8): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range_utf8): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8): Likewise. (selftest::test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise. (selftest::test_one_liner_many_fixits_1_utf8): Likewise. (selftest::test_one_liner_many_fixits_2_utf8): Likewise. (selftest::test_one_liner_labels_utf8): 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_utf8): 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. From-SVN: r279152 --- gcc/ChangeLog | 53 +++++ gcc/c-family/ChangeLog | 7 + gcc/c-family/c-format.c | 6 +- gcc/c-family/c-opts.c | 1 + gcc/diagnostic-show-locus.c | 211 ++++++------------ gcc/diagnostic.c | 2 + gcc/fortran/ChangeLog | 5 + gcc/fortran/error.c | 1 + gcc/testsuite/ChangeLog | 6 + .../diagnostic_plugin_test_show_locus.c | 1 + 10 files changed, 148 insertions(+), 145 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0a0336268e2..704403dabc1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,56 @@ +2019-12-09 David Malcolm + + * diagnostic-show-locus.c (diagnostic_show_locus): Remove initial + newline. + (selftest::test_diagnostic_show_locus_unknown_location): Remove + initial newline from expected outputs. + (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_one_liner_simple_caret_utf8): Likewise. + (selftest::test_one_liner_caret_and_range_utf8): Likewise. + (selftest::test_one_liner_multiple_carets_and_ranges_utf8): + Likewise. + (selftest::test_one_liner_fixit_insert_before_utf8): Likewise. + (selftest::test_one_liner_fixit_insert_after_utf8): Likewise. + (selftest::test_one_liner_fixit_remove_utf8): Likewise. + (selftest::test_one_liner_fixit_replace_utf8): Likewise. + (selftest::test_one_liner_fixit_replace_non_equal_range_utf8): + Likewise. + (selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8): + Likewise. + (selftest::test_one_liner_fixit_validation_adhoc_locations_utf8): + Likewise. + (selftest::test_one_liner_many_fixits_1_utf8): Likewise. + (selftest::test_one_liner_many_fixits_2_utf8): Likewise. + (selftest::test_one_liner_labels_utf8): 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_utf8): 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. + 2019-12-09 Martin Sebor PR middle-end/92761 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 8e74736988e..09d7a040726 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2019-12-09 David Malcolm + + * c-format.c (selftest::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. + 2019-12-06 Jakub Jelinek * c-cppbuiltin.c (c_cpp_builtins): Don't define __cpp_consteval for diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 519bc8f0af1..0be13496d8f 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -5392,16 +5392,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 c913291c07c..c3ad78e9735 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 9cd16952ce0..c87603caf41 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -2530,8 +2530,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) @@ -2766,7 +2764,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 @@ -2788,8 +2786,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)); } @@ -2806,8 +2803,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)); } @@ -2840,8 +2836,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)); } @@ -2856,8 +2851,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)); @@ -2875,8 +2869,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)); @@ -2899,8 +2892,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)); @@ -2912,8 +2904,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)); @@ -2925,8 +2916,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" @@ -2943,8 +2933,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" @@ -2961,8 +2950,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" @@ -2983,8 +2971,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)); @@ -3008,8 +2995,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", @@ -3034,8 +3020,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)); @@ -3068,8 +3053,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)); @@ -3085,8 +3069,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)); @@ -3102,8 +3085,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)); @@ -3122,8 +3104,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)); @@ -3145,8 +3126,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)); @@ -3182,8 +3162,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", @@ -3195,8 +3174,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)); } @@ -3213,8 +3191,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" @@ -3235,8 +3212,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" @@ -3255,8 +3231,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", @@ -3275,8 +3250,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" @@ -3311,8 +3285,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" @@ -3335,8 +3308,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)); } @@ -3415,8 +3387,7 @@ test_one_liner_simple_caret_utf8 () location_t caret = linemap_position_for_column (line_table, 18); rich_location richloc (line_table, caret); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3436,8 +3407,7 @@ test_one_liner_caret_and_range_utf8 () location_t loc = make_location (caret, start, finish); rich_location richloc (line_table, loc); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3473,8 +3443,7 @@ test_one_liner_multiple_carets_and_ranges_utf8 () 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" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3493,8 +3462,7 @@ test_one_liner_fixit_insert_before_utf8 () rich_location richloc (line_table, caret); richloc.add_fixit_insert_before ("&"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3516,8 +3484,7 @@ test_one_liner_fixit_insert_after_utf8 () rich_location richloc (line_table, foo); richloc.add_fixit_insert_after ("[0]"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3539,8 +3506,7 @@ test_one_liner_fixit_remove_utf8 () rich_location richloc (line_table, dot); richloc.add_fixit_remove (); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3562,8 +3528,7 @@ test_one_liner_fixit_replace_utf8 () rich_location richloc (line_table, field); richloc.add_fixit_replace ("m_\xf0\x9f\x98\x82_field\xcf\x80"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3592,8 +3557,7 @@ test_one_liner_fixit_replace_non_equal_range_utf8 () 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" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3623,8 +3587,7 @@ test_one_liner_fixit_replace_equal_secondary_range_utf8 () 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" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3662,8 +3625,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3683,8 +3645,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3704,8 +3665,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3728,8 +3688,7 @@ test_one_liner_many_fixits_1_utf8 () richloc.add_fixit_insert_before (i & 1 ? "@" : "\xcf\x80"); ASSERT_EQ (1, richloc.get_num_fixit_hints ()); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3760,8 +3719,7 @@ test_one_liner_many_fixits_2_utf8 () ASSERT_EQ (nlocs, richloc.get_num_fixit_hints ()); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3811,8 +3769,7 @@ test_one_liner_labels_utf8 () { test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3840,8 +3797,7 @@ test_one_liner_labels_utf8 () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3866,8 +3822,7 @@ test_one_liner_labels_utf8 () test_diagnostic_context dc; diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " \xf0\x9f\x98\x82" + ASSERT_STREQ (" \xf0\x9f\x98\x82" "_foo = \xcf\x80" "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" @@ -3973,8 +3928,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)); } @@ -4038,8 +3992,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)); @@ -4059,8 +4012,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" @@ -4083,8 +4035,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" @@ -4294,8 +4245,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", @@ -4361,8 +4311,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" @@ -4379,8 +4328,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" @@ -4401,8 +4349,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", @@ -4422,8 +4369,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", @@ -4441,8 +4387,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", @@ -4507,8 +4452,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_) richloc.add_fixit_insert_after (")"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " f\xf0\x9f\x98\x82" + ASSERT_STREQ (" f\xf0\x9f\x98\x82" " *f = (f\xf0\x9f\x98\x82" " *)ptr->field\xcf\x80" ";\n" @@ -4580,8 +4524,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_) richloc.add_fixit_insert_after (")"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " f\xf0\x9f\x98\x82" + ASSERT_STREQ (" f\xf0\x9f\x98\x82" " *f = (f\xf0\x9f\x98\x82" " *)ptr->field\xcf\x80" ";\n" @@ -4601,8 +4544,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_) richloc.add_fixit_insert_after (")"); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " f\xf0\x9f\x98\x82" + ASSERT_STREQ (" f\xf0\x9f\x98\x82" " *f = (f\xf0\x9f\x98\x82" " *)ptr->field\xcf\x80" ";\n" @@ -4626,8 +4568,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_) ASSERT_EQ (1, richloc.get_num_fixit_hints ()); diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " f\xf0\x9f\x98\x82" + ASSERT_STREQ (" f\xf0\x9f\x98\x82" " *f = (f\xf0\x9f\x98\x82" " *)ptr->field\xcf\x80" ";\n" @@ -4651,8 +4592,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_) /* But the corrections are. */ diagnostic_show_locus (&dc, &richloc, DK_ERROR); - ASSERT_STREQ ("\n" - " f\xf0\x9f\x98\x82" + ASSERT_STREQ (" f\xf0\x9f\x98\x82" " *f = (f\xf0\x9f\x98\x82" " *)ptr->field\xcf\x80" ";\n" @@ -4676,8 +4616,7 @@ test_overlapped_fixit_printing_utf8 (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" - " f\xf0\x9f\x98\x82" + ASSERT_STREQ (" f\xf0\x9f\x98\x82" " *f = (f\xf0\x9f\x98\x82" " *)ptr->field\xcf\x80" ";\n" @@ -4748,8 +4687,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)); @@ -4771,8 +4709,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", @@ -4815,8 +4752,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", @@ -4828,8 +4764,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", @@ -4845,8 +4780,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)); } @@ -4894,8 +4828,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" @@ -4910,8 +4843,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" @@ -4954,8 +4886,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)); } @@ -4999,8 +4930,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", @@ -5043,8 +4973,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 a29bcf155e2..d6604e6fd41 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/ChangeLog b/gcc/fortran/ChangeLog index 01866d5eec0..bbc00aec2bc 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2019-12-09 David Malcolm + + * error.c (gfc_diagnostic_starter): Add pp_newline call before + call to diagnostic_show_locus. + 2019-12-09 Frederik Harwath * trans-openmp.c (gfc_trans_omp_reduction_list): Pass correct location for each diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index b20aa86b155..03de73ecb35 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/ChangeLog b/gcc/testsuite/ChangeLog index 88c5a051e37..2f6f7afe014 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-12-09 David Malcolm + + * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c + (custom_diagnostic_finalizer): Add pp_newline call before call to + diagnostic_show_locus. + 2019-12-09 Paolo Carlini * c-c++-common/Wcast-align.c: Check location(s) too. 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 153bdb2fd89..482dbda47f7 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); -- 2.30.2