@@ -169,7 +169,7 @@ c_diagnostic_finalizer (diagnostic_context *context,
finalizer -- for tokens resulting from macro expansion. */
virt_loc_aware_diagnostic_finalizer (context, diagnostic);
pp_destroy_prefix (context->printer);
- pp_newline_and_flush (context->printer);
+ pp_flush (context->printer);
}
/* Common default settings for diagnostics. */
@@ -685,6 +685,9 @@ layout::print_any_fixits (int row, const rich_location *richloc)
}
}
}
+
+ /* Add a trailing newline, if necessary. */
+ move_to_column (&column, 0);
}
/* Return true if (ROW/COLUMN) is within a range of the layout.
@@ -799,6 +802,8 @@ void
diagnostic_show_locus (diagnostic_context * context,
const diagnostic_info *diagnostic)
{
+ pp_newline (context->printer);
+
if (!context->show_caret
|| diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
|| diagnostic_location (diagnostic, 0) == context->last_location)
@@ -806,8 +811,6 @@ diagnostic_show_locus (diagnostic_context * context,
context->last_location = diagnostic_location (diagnostic, 0);
- pp_newline (context->printer);
-
const char *saved_prefix = pp_get_prefix (context->printer);
pp_set_prefix (context->printer, NULL);
@@ -546,7 +546,7 @@ default_diagnostic_finalizer (diagnostic_context *context,
{
diagnostic_show_locus (context, diagnostic);
pp_destroy_prefix (context->printer);
- pp_newline_and_flush (context->printer);
+ pp_flush (context->printer);
}
/* Interface to specify diagnostic kind overrides. Returns the
@@ -879,37 +879,6 @@ diagnostic_append_note (diagnostic_context *context,
saved_prefix = pp_get_prefix (context->printer);
pp_set_prefix (context->printer,
diagnostic_build_prefix (context, &diagnostic));
- pp_newline (context->printer);
- pp_format (context->printer, &diagnostic.message);
- pp_output_formatted_text (context->printer);
- pp_destroy_prefix (context->printer);
- pp_set_prefix (context->printer, saved_prefix);
- diagnostic_show_locus (context, &diagnostic);
- va_end (ap);
-}
-
-/* Same as diagnostic_append_note, but at RICHLOC. */
-
-void
-diagnostic_append_note_at_rich_loc (diagnostic_context *context,
- rich_location *richloc,
- const char * gmsgid, ...)
-{
- diagnostic_info diagnostic;
- va_list ap;
- const char *saved_prefix;
-
- va_start (ap, gmsgid);
- diagnostic_set_info (&diagnostic, gmsgid, &ap, richloc, DK_NOTE);
- if (context->inhibit_notes_p)
- {
- va_end (ap);
- return;
- }
- saved_prefix = pp_get_prefix (context->printer);
- pp_set_prefix (context->printer,
- diagnostic_build_prefix (context, &diagnostic));
- pp_newline (context->printer);
pp_format (context->printer, &diagnostic.message);
pp_output_formatted_text (context->printer);
pp_destroy_prefix (context->printer);
@@ -293,10 +293,6 @@ extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
ATTRIBUTE_GCC_DIAG(2,0);
extern void diagnostic_append_note (diagnostic_context *, location_t,
const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
-extern void diagnostic_append_note_at_rich_loc (diagnostic_context *,
- rich_location *,
- const char *, ...)
- ATTRIBUTE_GCC_DIAG(3,4);
#endif
extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *);
void default_diagnostic_starter (diagnostic_context *, diagnostic_info *);
@@ -1096,7 +1096,6 @@ gfc_diagnostic_starter (diagnostic_context *context,
/* Fortran uses an empty line between locus and caret line. */
pp_newline (context->printer);
diagnostic_show_locus (context, diagnostic);
- pp_newline (context->printer);
/* If the caret line was shown, the prefix does not contain the
locus. */
pp_set_prefix (context->printer, kind_prefix);
@@ -667,7 +667,6 @@ pp_output_formatted_text (pretty_printer *pp)
const char **args = chunk_array->args;
gcc_assert (buffer->obstack == &buffer->formatted_obstack);
- gcc_assert (buffer->line_length == 0);
/* This is a third phase, first 2 phases done in pp_format_args.
Now we actually print it. */
@@ -71,6 +71,9 @@ set plugin_test_list [list \
{ diagnostic_plugin_show_trees.c \
diagnostic-test-show-trees-1.c } \
{ levenshtein_plugin.c levenshtein-test-1.c } \
+ { pr69006_plugin.c \
+ pr69006-test-1.c \
+ pr69006-test-2.c } \
]
foreach plugin_test $plugin_test_list {
new file mode 100644
@@ -0,0 +1,12 @@
+/* Placeholder C source file for testing PR other/69006.
+ This testcase (implicitly) tests the newlines seen with
+ -fno-diagnostics-show-caret. */
+
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+int
+main (int argc, char **argv)
+{
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,11 @@
+/* Placeholder C source file for testing PR other/69006.
+ This testcase tests the newlines seen with -fdiagnostics-show-caret. */
+
+/* { dg-do compile } */
+/* { dg-options "-O -fdiagnostics-show-caret" } */
+
+int
+main (int argc, char **argv)
+{
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,64 @@
+/* Plugin for verifying absence of stray newlines in diagnostic output
+ (PR other/69006). */
+
+#include "config.h"
+#include "gcc-plugin.h"
+#include "system.h"
+#include "coretypes.h"
+#include "diagnostic.h"
+
+int plugin_is_GPL_compatible;
+
+static int count_newlines (const char *text)
+{
+ gcc_assert (text);
+ int num_newlines = 0;
+ while (*text)
+ if (*(text++) == '\n')
+ num_newlines++;
+ return num_newlines;
+}
+
+/* Callback handler for the PLUGIN_FINISH_UNIT event.
+ Turn off flushing of diagnostics, and inject one,
+ and verify the newlines within the resulting unflushed
+ buffer. */
+
+static void
+on_finish_unit (void */*gcc_data*/, void */*user_data*/)
+{
+ output_buffer *buff = pp_buffer (global_dc->printer);
+
+ buff->flush_p = false;
+ warning_at (input_location, 0, "this is a warning");
+
+ /* buff should now contain a NIL-terminated printing of the above
+ diagnostic. */
+ const char *text = (const char *) obstack_base (buff->obstack);
+ gcc_assert (strstr (text, "this is a warning"));
+
+ /* Verify that we have the correct number of newline characters.
+ If we're printing source code, we expect 3 newlines:
+ "path-of-source.c:9:1: warning: this is a warning\n"
+ " }\n"
+ " ^\n"
+ Otherwise, we expect just 1 newline (for the first of the lines above). */
+ int expected_newlines = global_dc->show_caret ? 3 : 1;
+ int num_newlines = count_newlines (text);
+ gcc_assert (num_newlines == expected_newlines);
+
+ /* Verify that we don't have a blank line. */
+ gcc_assert (!strstr (text, "\n\n"));
+}
+
+int
+plugin_init (struct plugin_name_args *plugin_info,
+ struct plugin_gcc_version */*version*/)
+{
+ register_callback (plugin_info->base_name,
+ PLUGIN_FINISH_UNIT,
+ on_finish_unit,
+ NULL); /* void *user_data */
+
+ return 0;
+}