https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98011

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Regarding OpenACC: There is something going wrong here (-fopenacc):

../testsuite/gfortran.dg/goacc/sentinel-free-form.f95:13:6:

   13 |   !$ acc parallel ! { dg-error "Unclassifiable statement" }
      |      1
Error: Unclassifiable statement at (1)

I do not understand why it parses '!$'. It should regard it as comment; that's
not OpenMP!

 * * *

I wrote (for OpenMP's conditional compilation sentinel):
> In free-form source code: "Initial lines must have a space after the 
> sentinel".

I wonder whether checking this will break any real-world code.
Otherwise, the following patch would work.

We could also add a warning similar to the OpenACC warning:
  Warning: !$ACC at (1) starts a commented line as it neither is followed by a
space nor is a continuation line
to mitigate the real-world code issue.

--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -1866,10 +1866,11 @@ load_line (FILE *input, gfc_char_t **pbuf, int
*pbuflen, 

       /* For truncation and tab warnings, set seen_comment to false if one has
         either an OpenMP or OpenACC directive - or a !GCC$ attribute.  If
-        OpenMP is enabled, use '!$' as as conditional compilation sentinel
-        and OpenMP directive ('!$omp').  */
-      if (seen_comment && first_comment && flag_openmp && comment_ix + 1 == i
-         && c == '$')
+        OpenMP is enabled, use '!$' as as conditional compilation sentinel. 
*/
+      if (seen_comment && first_comment && flag_openmp
+         && ((gfc_current_form != FORM_FREE && comment_ix + 1 == i && c ==
'$')
+             || (gfc_current_form == FORM_FREE && comment_ix + 2 == i
+                 && (*pbuf)[comment_ix+1] == '$' && c == ' ')))
        first_comment = seen_comment = false;
       if (seen_comment && first_comment && comment_ix + 4 == i)
        {
@@ -1884,6 +1885,12 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pbuflen, 
              && ((*pbuf)[comment_ix+3] == 'c' || (*pbuf)[comment_ix+3] == 'C')
              && (c == 'c' || c == 'C'))
            first_comment = seen_comment = false;
+         if (flag_openmp
+             && (*pbuf)[comment_ix+1] == '$'
+             && ((*pbuf)[comment_ix+2] == 'o' || (*pbuf)[comment_ix+2] == 'O')
+             && ((*pbuf)[comment_ix+3] == 'm' || (*pbuf)[comment_ix+3] == 'M')
+             && (c == 'p' || c == 'P'))
+           first_comment = seen_comment = false;
        }

       /* Vendor extension: "<tab>1" marks a continuation line.  */

Reply via email to