[Patch] Fortran: Improve OpenMP/OpenACC syntax diagnostic
Tobias Burnus
tburnus@baylibre.com
Fri Jun 12 14:29:17 GMT 2026
This affects the generic 'parse.c' i.e. someone else might want
to have a look - and comments in general are welcome, however,
the change should only affect OpenMP/OpenACC as the new
match_word booleans default to the current behavior.
* * *
The MOTIVATION for this patch was in particular 'omp declare reduction'
that has both a rather complex syntax and often just shows the error
3 | !$omp declare reduction(+:t)
| 1
Error: Unclassifiable OpenMP directive at (1)
pointing to the directive name instead to the location where actually
something went wrong. Additionally, unknown directive and parsing
error are two separate things - and should have different error
messages!
The new code produces:
3 | !$omp declare reduction(+:t)
| 1
Error: Syntax error in statement at (1)
which shows that the directive is known and points to the column
where the error occurred.
(Still, 'declare reduction' could be made much more user friendly.)
* * *
Note:
As the parsing is rather complex and fragile, the 'follows space'
check is handled as after eating the directive name + peeking at
the next character instead of matching keyword + " " as that will
fail with the current assumptions in openmp.cc. While it only
works with free form text, it permits to state for 'cancellation'
that that's unknown - while for fixed form it complains
after 'cancel' that 'lation' is a syntax error, which is not as
nice but also works.
Likewise, for not resetting the parsing after MATCH_ERROR: This
will cause a few errors with the current testsuite, depending how
exactly one implements it. Thus, it is not used.
If there are no comments, I will apply this patch later today.
(Later comments are welcome as well.)
Tobias
PS: Looks as if 'declare reduction' could do with some more
explicit error diagnostic.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-omp-parse-diagnostic.diff
Type: text/x-patch
Size: 16078 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20260612/ef12bf28/attachment.bin>
More information about the Fortran
mailing list