Here's an updated version of this patch which adds a testcase to the DejaGnu test suite, using *<< and *>> for a multiline comment (used to express a fragment of the expected output on stderr).
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu, but I *haven't* tested this patch with the NIST testsuite. OK for trunk? Blurb follows: This patch changes the output on the simple test I tried from: $ ./gcobol -B. hello.cob -S hello.cob:2:8: error: syntax error, unexpected NAME, expecting FUNCTION or PROGRAM-ID 2 | porgram-id. hello. | ^ cobol1: error: failed compiling hello.cob to: $ ./gcobol -B. hello.cob -S hello.cob:2:8: error: syntax error, unexpected NAME, expecting FUNCTION or PROGRAM-ID 2 | porgram-id. hello. | ^~~~~~~~~~~ cobol1: error: failed compiling hello.cob gcc/cobol/ChangeLog: * util.cc (gcc_location_set_impl): Capture the start and end of "loc" as a range, rather than just the (last_line, first_column). gcc/testsuite/ChangeLog: * cobol.dg/typo-1.cob: New test. --- gcc/cobol/util.cc | 16 ++++++++++++++-- gcc/testsuite/cobol.dg/typo-1.cob | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/cobol.dg/typo-1.cob diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index 6ade146b5dda..aba4a1003554 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -1857,11 +1857,23 @@ cobol_filename_restore() { static location_t token_location; +/* Update global token_location with a location_t expressing a source + range with start and caret at the first line/column of LOC, and + finishing at the last line/column of LOC. */ + template <typename LOC> static void gcc_location_set_impl( const LOC& loc ) { - token_location = linemap_line_start( line_table, loc.last_line, 80 ); - token_location = linemap_position_for_column( line_table, loc.first_column); + const location_t start_line + = linemap_line_start( line_table, loc.first_line, 80 ); + const location_t token_start + = linemap_position_for_column( line_table, loc.first_column); + const location_t finish_line + = linemap_line_start( line_table, loc.last_line, 80 ); + const location_t token_finish + = linemap_position_for_column( line_table, loc.last_column); + token_location + = make_location (token_start, token_start, token_finish); location_dump(__func__, __LINE__, "parser", loc); } diff --git a/gcc/testsuite/cobol.dg/typo-1.cob b/gcc/testsuite/cobol.dg/typo-1.cob new file mode 100644 index 000000000000..a806863db190 --- /dev/null +++ b/gcc/testsuite/cobol.dg/typo-1.cob @@ -0,0 +1,15 @@ +*> { dg-options "-fdiagnostics-show-caret" } +*> { dg-do compile } + + identification division. + porgram-id. hello. *> { dg-error "8: syntax error, unexpected NAME, expecting FUNCTION or PROGRAM-ID" } + procedure division. + display "Hello World!". + stop run. + +*<< +{ dg-begin-multiline-output "" } + porgram-id. hello. + ^~~~~~~~~~~ +{ dg-end-multiline-output "" } +*>> -- 2.26.3