[Patch][Fortran] Vastly improve error message during parsing – simple patch for OpenMP/OpenACC directives

Tobias Burnus tobias@codesourcery.com
Wed Oct 2 09:25:00 GMT 2019


Simple patch – large effect.

Currently, gfortran prints for any parsing issue in !$omp (-fopenmp) and 
likewise for !$acc (-fopenacc) just:

     8 | !$omp target data  map(to:a) is_device_ptr(a)
       |      1
Error: Unclassifiable OpenMP directive at (1)

This patch adds a new error message – such that the error text is better 
and, in particular, the error location makes sense:

     8 | !$omp target data  map(to:a) is_device_ptr(a)
       |                              1
Error: Failed to match clause at (1)

(is_device is invalid as it is only permitted for "target" and not 
"target data").


In openmp.c, I now write a more explicit (and correct) error message, 
unless–  in a rare case – an error message has already been printed before.

parse.c: In order to get this to work properly, two things need to 
happen in parse.c: First, once an error message is printed, we don't 
fall through matching the next item – otherwise, one gets once the error 
above for "target data" plus one for  "target" (when parse the "clause" 
"data"). – But if the directive name has matched, we know for sure we 
are in the directive. Thus, the MATCH_ERROR must come from a clause.* – 
Secondly, reverting the location (undo_new_statement) should be avoided 
such that %C points to the right location.  (For buffered messages, it 
is evaluated at buffer-flush time not when gfc_{error,warning} is called.)

OK for the trunk?

Tobias

PS: Without my %C patch, the error location would be not under the "i" 
of "is_device_ptr" but before the "i" under the space; the old 
"Unclassifiable" message is from GCC 9 and, hence, "1" is under the space.
Please consider approving that patch as well: 
https://gcc.gnu.org/ml/fortran/2019-10/msg00010.html

[* That's different to normal Fortran parsing – especially with 
fixed-form which ignores spaces: "d o i = complex_expr, …": Until 
parsing the "," it can be both an assignment to "doi" or a loop ("do i = 
…"). But here we know.]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: omp-decl-parse.diff
Type: text/x-patch
Size: 35628 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20191002/4be88e3b/attachment.bin>


More information about the Gcc-patches mailing list