diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-02-12 19:18:03 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-02-12 19:18:03 +0000 |
commit | 876217ae71cf0b34490f8f53bb2a12d99d8baa7a (patch) | |
tree | 22a70a51fef5f5d79fbd3d50832a5ca8535979ad /gcc/testsuite/lib | |
parent | 8dccd19b3be7d3b94c6d3e0cbc7674d12314e909 (diff) | |
download | gcc-876217ae71cf0b34490f8f53bb2a12d99d8baa7a.zip gcc-876217ae71cf0b34490f8f53bb2a12d99d8baa7a.tar.gz gcc-876217ae71cf0b34490f8f53bb2a12d99d8baa7a.tar.bz2 |
PR other/69554: avoid excessive source printing for widely-separated locations
gcc/ChangeLog:
PR other/69554
* diagnostic-show-locus.c (struct line_span): New struct.
(layout::get_first_line): Delete.
(layout::get_last_line): Delete.
(layout::get_num_line_spans): New member function.
(layout::get_line_span): Likewise.
(layout::print_heading_for_line_span_index_p): Likewise.
(layout::get_expanded_location): Likewise.
(layout::calculate_line_spans): Likewise.
(layout::m_first_line): Delete.
(layout::m_last_line): Delete.
(layout::m_line_spans): New field.
(layout::layout): Update comment. Replace m_first_line and
m_last_line with m_line_spans, replacing their initialization
with a call to calculate_line_spans.
(diagnostic_show_locus): When printing source lines and
annotations, rather than looping over a single span
of lines, instead loop over each line_span within
the layout, with an inner loop over the lines within them.
Call the context's start_span callback when changing line spans.
* diagnostic.c (diagnostic_initialize): Initialize start_span.
(diagnostic_build_prefix): Break out the building of the location
part of the string into...
(diagnostic_get_location_text): ...this new function, rewriting
it from nested ternary expressions to a sequence of "if"
statements.
(default_diagnostic_start_span_fn): New function.
* diagnostic.h (diagnostic_start_span_fn): New typedef.
(diagnostic_context::start_span): New field.
(default_diagnostic_start_span_fn): New prototype.
gcc/fortran/ChangeLog:
PR other/69554
* error.c (gfc_diagnostic_start_span): New function.
(gfc_diagnostics_init): Initialize global_dc's start_span.
gcc/testsuite/ChangeLog:
PR other/69554
* gcc.dg/pr69554-1.c: New test.
* gfortran.dg/pr69554-1.F90: New test.
* gfortran.dg/pr69554-2.F90: New test.
* lib/gcc-dg.exp (proc dg-locus): New function.
* lib/gfortran-dg.exp (proc gfortran-dg-test): Update comment to
distinguish between the caret-printing and non-caret-printing
cases. If caret-printing has been explicitly enabled, bail out
without attempting to fix up the output.
From-SVN: r233386
Diffstat (limited to 'gcc/testsuite/lib')
-rw-r--r-- | gcc/testsuite/lib/gcc-dg.exp | 27 | ||||
-rw-r--r-- | gcc/testsuite/lib/gfortran-dg.exp | 19 |
2 files changed, 44 insertions, 2 deletions
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 3dd8564..b732b54 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -988,6 +988,33 @@ proc dg-message { args } { process-message saved-dg-warning "" $args } +# Look for a location marker of the form +# file:line:column: +# with no extra text (e.g. a line-span separator). + +proc dg-locus { args } { + upvar dg-messages dg-messages + + # Process the dg- directive, including adding the regular expression + # to the new message entry in dg-messages. + set msgcnt [llength ${dg-messages}] + eval saved-dg-warning $args + + # If the target expression wasn't satisfied there is no new message. + if { [llength ${dg-messages}] == $msgcnt } { + return; + } + + # Get the entry for the new message. Prepend the message prefix to + # the regular expression and make it match a single line. + set newentry [lindex ${dg-messages} end] + set expmsg [lindex $newentry 2] + + set newentry [lreplace $newentry 2 2 $expmsg] + set dg-messages [lreplace ${dg-messages} end end $newentry] + verbose "process-message:\n${dg-messages}" 2 +} + # Check the existence of a gdb in the path, and return true if there # is one. # diff --git a/gcc/testsuite/lib/gfortran-dg.exp b/gcc/testsuite/lib/gfortran-dg.exp index 52bb341..6b7f98b 100644 --- a/gcc/testsuite/lib/gfortran-dg.exp +++ b/gcc/testsuite/lib/gfortran-dg.exp @@ -26,7 +26,15 @@ proc gfortran-dg-test { prog do_what extra_tool_flags } { set comp_output [lindex $result 0] set output_file [lindex $result 1] - # gfortran error messages look like this: + # gcc's default is to print the caret and source code, but + # most test cases implicitly use the flag -fno-diagnostics-show-caret + # to disable caret (and source code) printing. + # + # However, a few test cases override this back to the default by + # explicily supplying "-fdiagnostics-show-caret", so that we can have + # test coverage for caret/source code printing. + # + # gfortran error messages with caret-printing look like this: # [name]:[locus]: # # some code @@ -49,7 +57,14 @@ proc gfortran-dg-test { prog do_what extra_tool_flags } { # 1 2 # Error: Some error at (1) and (2) # - # or + # If this is such a test case, skip the rest of this function, so + # that the test case can explicitly verify the output that it expects. + if {[string first "-fdiagnostics-show-caret" $extra_tool_flags] >= 0} { + return [list $comp_output $output_file] + } + + # Otherwise, caret-printing is disabled. + # gfortran errors with caret-printing disabled look like this: # [name]:[locus]: Error: Some error # or # [name]:[locus]: Error: (1) |