Fortran improves OpenMP/OpenACC syntax diagnostics
Fortran OpenMP/OpenACC syntax errors now yield more informative 'Syntax error in statement' messages, improving diagnostic quality.
The Fortran front end in GCC now provides more precise and helpful error messages for OpenMP and OpenACC syntax mistakes. Previously, a generic “Unclassifiable OpenMP/OpenACC directive” error was often reported, even for valid directives with syntax errors, because internal matching logic would reset the error locus. The updated parser now retains more context and reports “Syntax error in statement” with a correct pointer to the error location, making it easier for developers to identify and fix issues in their parallel programming directives.
In Details
This change refines the error reporting mechanism within the Fortran parser (parse.cc), specifically targeting OpenMP (decode_omp_directive) and OpenACC (decode_oacc_directive) directives. The match_word function, used for keyword matching, now includes no_substring and reject_stmt_on_error arguments. The issue stemmed from match_word resetting the locus upon a non-match, leading to loss of specific error context and generic "Unclassifiable" messages. By preserving locus information and checking for buffered messages, the parser can now emit a more accurate "Syntax error in stat…
For Context
When you write code in Fortran and use special instructions for parallel computing like OpenMP and OpenACC, the compiler needs to understand those instructions perfectly. This update improves the error messages you get if you make a mistake in these special instructions. Before, if you had a typo or an incorrect syntax in an OpenMP or OpenACC directive, the compiler might just say it couldn't understand the directive at all, even if the directive name itself was correct. Now, the compiler is smarter; it will tell you there's a "Syntax error in statement" and point to the exact spot where the mistake is, making it much easier to find and fix the problem in your parallel code.