]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: More Fortran front-end fixes for metadirectives
authorKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 11 Feb 2022 15:42:50 +0000 (15:42 +0000)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Mon, 14 Feb 2022 15:54:22 +0000 (15:54 +0000)
This adds a check for declarative OpenMP directives in metadirective
variants (already present in the C/C++ front-ends), and fixes an
ICE when an empty metadirective (i.e. just '!$omp metadirective')
is presented.

2022-02-11  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/fortran/
* gfortran.h (is_omp_declarative_stmt): New.
* openmp.c (match_omp_metadirective): Reject declarative OpenMP
directives with 'sorry'.
* parse.c (parse_omp_metadirective_body): Check that state stack head
is non-null before dereferencing.
(is_omp_declarative_stmt): New.

gcc/testsuite/
* gfortran.dg/gomp/metadirective-2.f90 (main): Test empty
metadirective.

gcc/fortran/ChangeLog.omp
gcc/fortran/gfortran.h
gcc/fortran/openmp.c
gcc/fortran/parse.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90

index 070744413db6e1c7813ebbfe2b034944bb088bf0..e76884dbc0c88a3411faf466a0ebe1e4727ed1a4 100644 (file)
@@ -1,3 +1,12 @@
+2022-02-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * gfortran.h (is_omp_declarative_stmt): New.
+       * openmp.c (match_omp_metadirective): Reject declarative OpenMP
+       directives with 'sorry'.
+       * parse.c (parse_omp_metadirective_body): Check that state stack head
+       is non-null before dereferencing.
+       (is_omp_declarative_stmt): New.
+
 2022-02-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        * decl.c (gfc_match_end): Search for first previous state that is not
index 338dcad240ba52dfe38fb8cba0f1eb296884f6f2..f9b36ca5205cfebfbd669c7428f67c39b831c1ec 100644 (file)
@@ -3833,6 +3833,7 @@ bool gfc_parse_file (void);
 void gfc_global_used (gfc_gsymbol *, locus *);
 gfc_namespace* gfc_build_block_ns (gfc_namespace *);
 gfc_statement match_omp_directive (void);
+bool is_omp_declarative_stmt (gfc_statement);
 
 /* dependency.c */
 int gfc_dep_compare_functions (gfc_expr *, gfc_expr *, bool);
index 1f82e09f27006842bfd7f0c0bce3217a9105f277..43e5be004f99f71d4a50f8eb266a011182d920df 100644 (file)
@@ -5037,6 +5037,9 @@ match_omp_metadirective (bool begin_p)
       gfc_statement directive = match_omp_directive ();
       gfc_matching_omp_context_selector = false;
 
+      if (is_omp_declarative_stmt (directive))
+       sorry ("declarative directive variants are not supported");
+
       if (gfc_error_flag_test ())
        {
          gfc_current_locus = old_loc;
index 7d3aa9e0488bdbcca2350b0d18975db82b7ce8e7..00e2dda2f06591726215fa607e5327ed6292f9f7 100644 (file)
@@ -5820,7 +5820,8 @@ parse_omp_metadirective_body (gfc_statement omp_st)
 
       gfc_in_metadirective_body = old_in_metadirective_body;
 
-      *clause->code = *gfc_state_stack->head;
+      if (gfc_state_stack->head)
+       *clause->code = *gfc_state_stack->head;
       pop_state ();
 
       gfc_commit_symbols ();
@@ -7082,3 +7083,16 @@ is_oacc (gfc_state_data *sd)
       return false;
     }
 }
+
+/* Return true if ST is a declarative OpenMP statement.  */
+bool
+is_omp_declarative_stmt (gfc_statement st)
+{
+  switch (st)
+    {
+      case_omp_decl:
+       return true;
+      default:
+       return false;
+    }
+}
index 2b610c00ef3148cfde50528bfa98061491ba5a92..07bdb9d0645da33a7160bb28251dad2c1cabe9be 100644 (file)
@@ -1,3 +1,8 @@
+2022-02-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * gfortran.dg/gomp/metadirective-2.f90 (main): Test empty
+       metadirective.
+
 2022-02-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        * gfortran.dg/gomp/metadirective-8.f90: New.
index 06c324589d036332215db5dbb42a2aed3424aab9..cdd5e85068e180a241822e41f862e6455a2d8e65 100644 (file)
@@ -43,7 +43,7 @@ program main
     end do
   !$omp end metadirective
   
-  ! Test labels in the body
+  ! Test labels in the body.
   !$omp begin metadirective &
   !$omp&       when (device={arch("nvptx")}: parallel do) &
   !$omp&       when (device={arch("gcn")}: parallel)
@@ -56,4 +56,7 @@ program main
 20    continue
     end do
   !$omp end metadirective
+
+  ! Test empty metadirective.
+  !$omp metadirective
 end program