+2018-10-15 David Malcolm <dmalcolm@redhat.com>
+
+ * common.opt (fdiagnostics-minimum-margin-width=): New option.
+ * diagnostic-show-locus.c (layout::layout): Apply the minimum
+ margin width.
+ (layout::start_annotation_line): Only print up to 3 of the
+ margin character, to avoid touching the left-hand side.
+ (selftest::test_diagnostic_show_locus_fixit_lines): Update for
+ minimum margin width, as set by test_diagnostic_context's ctor.
+ (selftest::test_fixit_insert_containing_newline): Likewise.
+ (selftest::test_fixit_insert_containing_newline_2): Likewise.
+ (selftest::test_line_numbers_multiline_range): Clear
+ dc.min_margin_width.
+ * diagnostic.c (diagnostic_initialize): Initialize
+ min_margin_width.
+ * diagnostic.h (struct diagnostic_context): Add field
+ "min_margin_width".
+ * doc/invoke.texi: Add -fdiagnostics-minimum-margin-width=.
+ * opts.c (common_handle_option): Handle
+ OPT_fdiagnostics_minimum_margin_width_.
+ * selftest-diagnostic.c
+ (selftest::test_diagnostic_context::test_diagnostic_context):
+ Initialize min_margin_width to 6.
+ * toplev.c (general_init): Initialize global_dc->min_margin_width.
+
2018-10-15 David Malcolm <dmalcolm@redhat.com>
* gcc-rich-location.h (gcc_rich_location::add_location_if_nearby):
Common Var(flag_diagnostics_show_option) Init(1)
Amend appropriate diagnostic messages with the command line option that controls them.
+fdiagnostics-minimum-margin-width=
+Common Joined UInteger Var(diagnostics_minimum_margin_width) Init(6)
+Set minimum width of left margin of source code when showing source
+
fdisable-
Common Joined RejectNegative Var(common_deferred_options) Defer
-fdisable-[tree|rtl|ipa]-<pass>=range1+range2 disables an optimization pass.
/* If we're showing jumps in the line-numbering, allow at least 3 chars. */
if (m_line_spans.length () > 1)
m_linenum_width = MAX (m_linenum_width, 3);
+ /* If there's a minimum margin width, apply it (subtracting 1 for the space
+ after the line number. */
+ m_linenum_width = MAX (m_linenum_width, context->min_margin_width - 1);
/* Adjust m_x_offset.
Center the primary caret to fit in max_width; all columns
{
if (m_show_line_numbers_p)
{
- for (int i = 0; i < m_linenum_width; i++)
+ /* Print the margin. If MARGIN_CHAR != ' ', then print up to 3
+ of it, right-aligned, padded with spaces. */
+ int i;
+ for (i = 0; i < m_linenum_width - 3; i++)
+ pp_space (m_pp);
+ for (; i < m_linenum_width; i++)
pp_character (m_pp, margin_char);
pp_string (m_pp, " |");
}
dc.show_line_numbers_p = true;
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ ("\n"
- " 3 | y\n"
- " | .\n"
- "....\n"
- " 6 | : 0.0};\n"
- " | ^\n"
- " | =\n",
+ " 3 | y\n"
+ " | .\n"
+ "......\n"
+ " 6 | : 0.0};\n"
+ " | ^\n"
+ " | =\n",
pp_formatted_text (dc.printer));
}
}
dc.show_line_numbers_p = true;
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ ("\n"
- "2 | x = a;\n"
- "+ |+ break;\n"
- "3 | case 'b':\n"
- " | ^~~~~~~~~\n",
+ " 2 | x = a;\n"
+ " +++ |+ break;\n"
+ " 3 | case 'b':\n"
+ " | ^~~~~~~~~\n",
pp_formatted_text (dc.printer));
}
}
dc.show_line_numbers_p = true;
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ ("\n"
- "+ |+#include <stdio.h>\n"
- "1 | test (int ch)\n"
- "2 | {\n"
- "3 | putchar (ch);\n"
- " | ^~~~~~~\n",
+ " +++ |+#include <stdio.h>\n"
+ " 1 | test (int ch)\n"
+ " 2 | {\n"
+ " 3 | putchar (ch);\n"
+ " | ^~~~~~~\n",
pp_formatted_text (dc.printer));
}
}
test_diagnostic_context dc;
dc.show_line_numbers_p = true;
+ dc.min_margin_width = 0;
gcc_rich_location richloc (loc);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ ("\n"
context->colorize_source_p = false;
context->show_labels_p = false;
context->show_line_numbers_p = false;
+ context->min_margin_width = 0;
context->show_ruler_p = false;
context->parseable_fixits_p = false;
context->edit_context_ptr = NULL;
showing line numbers? */
bool show_line_numbers_p;
+ /* If printing source code, what should the minimum width of the margin
+ be? Line numbers will be right-aligned, and padded to this width. */
+ int min_margin_width;
+
/* Usable by plugins; if true, print a debugging ruler above the
source output. */
bool show_ruler_p;
-fdiagnostics-color=@r{[}auto@r{|}never@r{|}always@r{]} @gol
-fno-diagnostics-show-option -fno-diagnostics-show-caret @gol
-fno-diagnostics-show-labels -fno-diagnostics-show-line-numbers @gol
+-fdiagnostics-minimum-margin-width=@var{width} @gol
-fdiagnostics-parseable-fixits -fdiagnostics-generate-patch @gol
-fdiagnostics-show-template-tree -fno-elide-type @gol
-fno-show-column}
a left margin is printed, showing line numbers. This option suppresses this
left margin.
+@item -fdiagnostics-minimum-margin-width=@var{width}
+@opindex -fdiagnostics-minimum-margin-width
+This option controls the minimum width of the left margin printed by
+@option{-fdiagnostics-show-line-numbers}. It defaults to 6.
+
@item -fdiagnostics-parseable-fixits
@opindex fdiagnostics-parseable-fixits
Emit fix-it hints in a machine-parseable format, suitable for consumption
dc->show_option_requested = value;
break;
+ case OPT_fdiagnostics_minimum_margin_width_:
+ dc->min_margin_width = value;
+ break;
+
case OPT_fdump_:
/* Deferred. */
break;
show_labels_p = true;
show_column = true;
start_span = start_span_cb;
+ min_margin_width = 6;
}
test_diagnostic_context::~test_diagnostic_context ()
+2018-10-15 David Malcolm <dmalcolm@redhat.com>
+
+ * gcc.dg/missing-header-fixit-3.c: Update expected indentation
+ to reflect minimum margin width.
+ * gcc.dg/missing-header-fixit-4.c: Likewise.
+ * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c:
+ Likewise.
+ * gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c:
+ Likewise.
+ * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers-2.c:
+ New test.
+ * gcc.dg/plugin/plugin.exp (plugin_test_list): Add it.
+
2018-10-15 Tobias Burnus <burnus@net-b.de>
PR fortran/87597
/* { dg-message "include '<stdio.h>' or provide a declaration of 'printf'" "" { target *-*-* } 1 } */
#if 0
/* { dg-begin-multiline-output "" }
-9 | printf ("%i of %i\n", i, j);
- | ^~~~~~
+ 9 | printf ("%i of %i\n", i, j);
+ | ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
-+ |+#include <stdio.h>
-1 | /* Example of a fix-it hint that adds a #include directive,
+ +++ |+#include <stdio.h>
+ 1 | /* Example of a fix-it hint that adds a #include directive,
{ dg-end-multiline-output "" } */
#endif
}
/* { dg-warning "implicit declaration of function" "" { target *-*-* } printf } */
/* { dg-warning "incompatible implicit declaration" "" { target *-*-* } printf } */
/* { dg-begin-multiline-output "" }
-10 | printf ("%i of %i\n", i, j);
- | ^~~~~~
+ 10 | printf ("%i of %i\n", i, j);
+ | ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-message "include '<stdio.h>' or provide a declaration of 'printf'" "" { target *-*-* } 4 } */
/* { dg-begin-multiline-output "" }
-3 | #include "empty.h"
-+ |+#include <stdio.h>
-4 | int the_next_line;
+ 3 | #include "empty.h"
+ +++ |+#include <stdio.h>
+ 4 | int the_next_line;
{ dg-end-multiline-output "" } */
}
--- /dev/null
+/* { dg-do compile } */
+/* Verify "-fdiagnostics-minimum-margin-width=0". */
+/* { dg-options "-O -fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-minimum-margin-width=0" } */
+
+/* This is a collection of unittests for diagnostic_show_locus;
+ see the overview in diagnostic_plugin_test_show_locus.c.
+
+ In particular, note the discussion of why we need a very long line here:
+01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+ and that we can't use macros in this file. */
+
+void test_simple (void)
+{
+#if 0
+ myvar = myvar.x; /* { dg-warning "test" } */
+
+/* { dg-begin-multiline-output "" }
+15 | myvar = myvar.x;
+ | ~~~~~^~
+ { dg-end-multiline-output "" } */
+#endif
+}
myvar = myvar.x; /* { dg-warning "test" } */
/* { dg-begin-multiline-output "" }
-14 | myvar = myvar.x;
- | ~~~~~^~
+ 14 | myvar = myvar.x;
+ | ~~~~~^~
{ dg-end-multiline-output "" } */
#endif
}
+ second_function ()); /* { dg-warning "test" } */
/* { dg-begin-multiline-output "" }
-26 | x = (first_function ()
- | ~~~~~~~~~~~~~~~~~
-27 | + second_function ());
- | ^ ~~~~~~~~~~~~~~~~~~
- | |
- | label
+ 26 | x = (first_function ()
+ | ~~~~~~~~~~~~~~~~~
+ 27 | + second_function ());
+ | ^ ~~~~~~~~~~~~~~~~~~
+ | |
+ | label
{ dg-end-multiline-output "" } */
#endif
}
#if 0
float f = foo * bar; /* { dg-warning "95: test" } */
/* { dg-begin-multiline-output "" }
- | 0 0 0 0 0 0 1
- | 4 5 6 7 8 9 0
- | 0123456789012345678901234567890123456789012345678901234567890123456789
-43 | float f = foo * bar;
- | ~~~~^~~~~
- | |
- | label
- | bar * foo
+ | 0 0 0 0 0 1 1
+ | 5 6 7 8 9 0 1
+ | 3456789012345678901234567890123456789012345678901234567890123456789012
+ 43 | float f = foo * bar;
+ | ~~~~^~~~~
+ | |
+ | label 0
+ | bar * foo
{ dg-end-multiline-output "" } */
#endif
}
#if 0
int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */
/* { dg-begin-multiline-output "" }
-63 | int a[2][2] = { 0, 1 , 2, 3 };
- | ^~~~
- | { }
+ 63 | int a[2][2] = { 0, 1 , 2, 3 };
+ | ^~~~
+ | { }
{ dg-end-multiline-output "" } */
#endif
}
#if 0
int a;; /* { dg-warning "example of a removal hint" } */
/* { dg-begin-multiline-output "" }
-77 | int a;;
- | ^
- | -
+ 77 | int a;;
+ | ^
+ | -
{ dg-end-multiline-output "" } */
#endif
}
#if 0
gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */
/* { dg-begin-multiline-output "" }
-91 | gtk_widget_showall (dlg);
- | ^~~~~~~~~~~~~~~~~~
- | gtk_widget_show_all
+ 91 | gtk_widget_showall (dlg);
+ | ^~~~~~~~~~~~~~~~~~
+ | gtk_widget_show_all
{ dg-end-multiline-output "" } */
#endif
}
x = b;
}
/* { dg-begin-multiline-output "" }
-109 | x = a;
-+++ |+ break;
-110 | case 'b':
- | ^~~~~~~~
+ 109 | x = a;
+ +++ |+ break;
+ 110 | case 'b':
+ | ^~~~~~~~
{ dg-end-multiline-output "" } */
#endif
}
+ second_function ()); /* { dg-warning "test" } */
/* { dg-begin-multiline-output "" }
-14 | x = (\e[32m\e[Kfirst_function ()\e[m\e[K
- | \e[32m\e[K~~~~~~~~~~~~~~~~~\e[m\e[K
-15 | \e[01;35m\e[K+\e[m\e[K \e[34m\e[Ksecond_function ()\e[m\e[K);
- | \e[01;35m\e[K^\e[m\e[K \e[34m\e[K~~~~~~~~~~~~~~~~~~\e[m\e[K
- | \e[01;35m\e[K|\e[m\e[K
- | \e[01;35m\e[Klabel\e[m\e[K
+ 14 | x = (\e[32m\e[Kfirst_function ()\e[m\e[K
+ | \e[32m\e[K~~~~~~~~~~~~~~~~~\e[m\e[K
+ 15 | \e[01;35m\e[K+\e[m\e[K \e[34m\e[Ksecond_function ()\e[m\e[K);
+ | \e[01;35m\e[K^\e[m\e[K \e[34m\e[K~~~~~~~~~~~~~~~~~~\e[m\e[K
+ | \e[01;35m\e[K|\e[m\e[K
+ | \e[01;35m\e[Klabel\e[m\e[K
{ dg-end-multiline-output "" } */
#endif
}
diagnostic-test-show-locus-color.c \
diagnostic-test-show-locus-no-labels.c \
diagnostic-test-show-locus-bw-line-numbers.c \
+ diagnostic-test-show-locus-bw-line-numbers-2.c \
diagnostic-test-show-locus-color-line-numbers.c \
diagnostic-test-show-locus-parseable-fixits.c \
diagnostic-test-show-locus-generate-patch.c }\
= global_options_init.x_flag_diagnostics_show_line_numbers;
global_dc->show_option_requested
= global_options_init.x_flag_diagnostics_show_option;
+ global_dc->min_margin_width
+ = global_options_init.x_diagnostics_minimum_margin_width;
global_dc->show_column
= global_options_init.x_flag_show_column;
global_dc->internal_error = internal_error_function;