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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

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

Tobias Burnus-3
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?


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:

[* 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.]

omp-decl-parse.diff (35K) Download Attachment
Reply | Threaded
Open this post in threaded view

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

Jakub Jelinek


On Wed, Oct 02, 2019 at 11:24:46AM +0200, Tobias Burnus wrote:
> gcc/fortran/
> * openmp.c (gfc_match_omp_clauses): Show a clause-parsing
> error if none was rised before.
> * parse.c (matcha, matcho): If error occurred after
> OpenMP/OpenACC directive matched, do not try other directives.
> gcc/testsuite/
> * gfortran.dg/goacc/asyncwait-1.f95: Handle new error message.
> * gfortran.dg/goacc/asyncwait-2.f95: Likewise


> * gfortran.dg/goacc/asyncwait-3.f95: Likewise
> * gfortran.dg/goacc/asyncwait-4.f95: Likewise
> * gfortran.dg/goacc/default-2.f: Likewise
> * gfortran.dg/goacc/enter-exit-data.f95: Likewise
> * gfortran.dg/goacc/if.f95: Likewise
> * gfortran.dg/goacc/list.f95: Likewise
> * gfortran.dg/goacc/literal.f95: Likewise
> * gfortran.dg/goacc/loop-2-kernels-tile.f: Likewise95

95 should move before :

> * gfortran.dg/goacc/loop-2-parallel-tile.f95: Likewise
> * gfortran.dg/goacc/loop-7.f95: Likewise
> * gfortran.dg/goacc/parallel-kernels-cla: Likewiseuses.f95

Similarly for uses.f95

> * gfortran.dg/goacc/routine-6.f90: Likewise
> * gfortran.dg/goacc/several-directives.f95: Likewise
> * gfortran.dg/goacc/sie.f95: Likewise
> * gfortran.dg/goacc/tile-1.f90: Likewise
> * gfortran.dg/goacc/update-if_present-2.: Likewisef90

Similarly for f90

> * gfortran.dg/gomp/declare-simd-1.f90: Likewise
> * gfortran.dg/gomp/pr29759.f90: Likewise

Ok with the ChangeLog nits fixed.