public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kwok Yeung <kcy@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-11] openmp: More Fortran front-end fixes for metadirectives
Date: Mon, 14 Feb 2022 15:59:42 +0000 (GMT)	[thread overview]
Message-ID: <20220214155942.7DA08385842B@sourceware.org> (raw)

https://gcc.gnu.org/g:8cb0121af50eacb63098a79ff8c6deae05883c6f

commit 8cb0121af50eacb63098a79ff8c6deae05883c6f
Author: Kwok Cheung Yeung <kcy@codesourcery.com>
Date:   Fri Feb 11 15:42:50 2022 +0000

    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.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.

Diff:
---
 gcc/fortran/ChangeLog.omp                          |  9 +++++++++
 gcc/fortran/gfortran.h                             |  1 +
 gcc/fortran/openmp.c                               |  3 +++
 gcc/fortran/parse.c                                | 16 +++++++++++++++-
 gcc/testsuite/ChangeLog.omp                        |  5 +++++
 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 |  5 ++++-
 6 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 070744413db..e76884dbc0c 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -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
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 338dcad240b..f9b36ca5205 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -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);
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 1f82e09f270..43e5be004f9 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -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;
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
index 7d3aa9e0488..00e2dda2f06 100644
--- a/gcc/fortran/parse.c
+++ b/gcc/fortran/parse.c
@@ -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;
+    }
+}
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 2b610c00ef3..07bdb9d0645 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -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.
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


                 reply	other threads:[~2022-02-14 15:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220214155942.7DA08385842B@sourceware.org \
    --to=kcy@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).