[PATCH 6/7] openmp, fortran: Add Fortran support for parsing metadirectives
Kwok Cheung Yeung
kcy@codesourcery.com
Mon Feb 14 15:17:06 GMT 2022
This patch (again, to be applied on top of the current set of
metadirective patches) fixes two minor issues with metadirectives in the
Fortran front-end.
- 'sorry' is called if a declarative OpenMP directive is found in a
metadirective clause.
- An ICE that occurs with an empty metadirective (i.e. just '!$omp
metadirective' with nothing else) is fixed.
Thanks
Kwok
-------------- next part --------------
From 153b8dbd19cf90b1869be7f409d55d1ab5ba81d5 Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung <kcy@codesourcery.com>
Date: Fri, 11 Feb 2022 15:42:50 +0000
Subject: [PATCH 2/2] openmp: More Fortran front-end fixes for metadirectives
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/gfortran.h | 1 +
gcc/fortran/openmp.cc | 3 +++
gcc/fortran/parse.cc | 16 +++++++++++++++-
.../gfortran.dg/gomp/metadirective-2.f90 | 5 ++++-
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index bdb4b0f6aa5..37eb039b6d4 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3852,6 +3852,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);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 5e87e18ce0d..0071484817d 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -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;
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index cd18315697e..cb8acb3c68f 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -5841,7 +5841,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 ();
@@ -7081,3 +7082,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;
+ }
+}
diff --git a/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 b/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90
index 06c324589d0..cdd5e85068e 100644
--- a/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90
@@ -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
--
2.25.1
More information about the Gcc-patches
mailing list