]> 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>
Tue, 28 Jun 2022 20:55:19 +0000 (13:55 -0700)
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.cc (match_omp_metadirective): Reject declarative OpenMP
directives with 'sorry'.
* parse.cc (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.cc
gcc/fortran/parse.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90

index 180a54b17dc97f25b3e388f40d7bfdfb843a1d3b..bce274c0ea5292fee9ffc4e1d0b7d58542fa7dc1 100644 (file)
@@ -1,3 +1,12 @@
+2022-02-11  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * gfortran.h (is_omp_declarative_stmt): New.
+       * openmp.cc (match_omp_metadirective): Reject declarative OpenMP
+       directives with 'sorry'.
+       * parse.cc (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.cc (gfc_match_end): Search for first previous state that is not
index edc45ca09eed89e5d163d79a797f95ea2d7493f1..6099b2b9638a70b12081f7daab41817ab11ae44f 100644 (file)
@@ -3859,6 +3859,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.cc */
 int gfc_dep_compare_functions (gfc_expr *, gfc_expr *, bool);
index 3661271d4a986422cd6976ea9ced7864deddf92b..af54bd5315753d948bb016707fdab6a2047eb47c 100644 (file)
@@ -5151,6 +5151,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 e1eb81ce0731cab03f1b2531a261fd7d48b72207..1d216247bc3d8762c7e0cb8109f75d231664b909 100644 (file)
@@ -5859,7 +5859,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 ();
@@ -7125,3 +7126,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 2fc0f1d9b7d0cca940da0d4887207567113365af..2ca7567c25c7bcd75f8fe092b17e8b1b310249b5 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