public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] openmp, fortran: Check that event handles passed to detach clauses are not arrays [PR104131]
@ 2022-02-28 14:01 Kwok Cheung Yeung
  2022-02-28 14:07 ` Jakub Jelinek
  0 siblings, 1 reply; 18+ messages in thread
From: Kwok Cheung Yeung @ 2022-02-28 14:01 UTC (permalink / raw)
  To: gcc-patches, fortran, Jakub Jelinek, gscfq

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

Hello

This patch addresses PR fortran/104131 on the GCC bug tracker, where an 
ICE would occur if an array or co-array was passed as the event handle 
in the detach clause of a task.

Since the event handle is supposed to be a scalar of type 
omp_event_handle_kind, we can simply reject the event handle during 
parsing if it is any type of array, thereby preventing the situation 
leading to an ICE in the first place.

Okay for trunk?

Thanks

Kwok

[-- Attachment #2: 0001-openmp-fortran-Check-that-event-handles-passed-to-de.patch --]
[-- Type: text/plain, Size: 4057 bytes --]

From 8ed3b8bd793298f94bdefbdff32f91eaea1a9d70 Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung <kcy@codesourcery.com>
Date: Mon, 28 Feb 2022 12:34:22 +0000
Subject: [PATCH] openmp, fortran: Check that event handles passed to detach
 clauses are not arrays [PR104131]

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

gcc/fortran/

	PR fortran/104131
	* openmp.cc (gfc_match_omp_detach): Check that the event handle is not
	an array type.

gcc/testsuite/

	PR fortran/104131
	* gfortran.dg/gomp/pr104131.f90: New.
	* gfortran.dg/gomp/pr104131-2.f90: New.
	* gfortran.dg/gomp/task-detach-1.f90: Update expected error message.
---
 gcc/fortran/openmp.cc                            |  5 +++--
 gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90    | 10 ++++++++++
 gcc/testsuite/gfortran.dg/gomp/pr104131.f90      | 10 ++++++++++
 gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 |  2 +-
 4 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr104131.f90

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 19142c4d8d0..50a1c476009 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -531,9 +531,10 @@ gfc_match_omp_detach (gfc_expr **expr)
   if (gfc_match_variable (expr, 0) != MATCH_YES)
     goto syntax_error;
 
-  if ((*expr)->ts.type != BT_INTEGER || (*expr)->ts.kind != gfc_c_intptr_kind)
+  if ((*expr)->ts.type != BT_INTEGER || (*expr)->ts.kind != gfc_c_intptr_kind
+      || (*expr)->symtree->n.sym->as)
     {
-      gfc_error ("%qs at %L should be of type "
+      gfc_error ("%qs at %L should be a scalar of type "
 		 "integer(kind=omp_event_handle_kind)",
 		 (*expr)->symtree->n.sym->name, &(*expr)->where);
       return MATCH_ERROR;
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90 b/gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90
new file mode 100644
index 00000000000..8d10367ba3b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-fopenmp -fcoarray=single" }
+
+program p
+  use iso_c_binding, only: c_intptr_t
+  integer, parameter :: omp_event_handle_kind = c_intptr_t
+  integer (kind=omp_event_handle_kind) :: x[*]
+  !$omp task detach (x) ! { dg-error "'x' at \\\(1\\\) should be a scalar of type integer\\\(kind=omp_event_handle_kind\\\)" }
+  !$omp end task ! { dg-error "Unexpected !\\\$OMP END TASK statement at \\\(1\\\)" }
+end
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr104131.f90 b/gcc/testsuite/gfortran.dg/gomp/pr104131.f90
new file mode 100644
index 00000000000..70a2dedfd7f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr104131.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-fopenmp" }
+
+program p
+  use iso_c_binding, only: c_intptr_t
+  integer, parameter :: omp_event_handle_kind = c_intptr_t
+  integer(omp_event_handle_kind) :: x(1)
+  !$omp task detach(x) ! { dg-error "'x' at \\\(1\\\) should be a scalar of type integer\\\(kind=omp_event_handle_kind\\\)" }
+  !$omp end task ! { dg-error "Unexpected !\\\$OMP END TASK statement at \\\(1\\\)" }
+end
diff --git a/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 b/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90
index 020be13a8b6..b73db07b7c3 100644
--- a/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90
@@ -18,7 +18,7 @@ program task_detach_1
   !$omp task detach(x) mergeable ! { dg-error "'DETACH' clause at \\\(1\\\) must not be used together with 'MERGEABLE' clause" }
   !$omp end task
 
-  !$omp task detach(z) ! { dg-error "'z' at \\\(1\\\) should be of type integer\\\(kind=omp_event_handle_kind\\\)" }
+  !$omp task detach(z) ! { dg-error "'z' at \\\(1\\\) should be a scalar of type integer\\\(kind=omp_event_handle_kind\\\)" }
   !$omp end task ! { dg-error "Unexpected !\\\$OMP END TASK statement at \\\(1\\\)" }
   
   !$omp task detach (x) firstprivate (x) ! { dg-error "DETACH event handle 'x' in FIRSTPRIVATE clause at \\\(1\\\)" }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-03-02 17:31 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 14:01 [PATCH] openmp, fortran: Check that event handles passed to detach clauses are not arrays [PR104131] Kwok Cheung Yeung
2022-02-28 14:07 ` Jakub Jelinek
2022-02-28 14:27   ` Kwok Cheung Yeung
2022-02-28 15:54     ` Mikael Morin
2022-02-28 16:00       ` Jakub Jelinek
2022-02-28 17:33         ` Mikael Morin
2022-02-28 17:37           ` Jakub Jelinek
2022-02-28 18:38             ` Kwok Cheung Yeung
2022-02-28 20:37               ` Mikael Morin
2022-02-28 20:45                 ` Mikael Morin
2022-02-28 21:37                   ` Jakub Jelinek
2022-02-28 22:36                     ` Mikael Morin
2022-03-01  7:58                     ` Tobias Burnus
2022-03-01  8:16                       ` Jakub Jelinek
2022-03-01  9:17                         ` Tobias Burnus
2022-03-01 15:37                           ` Mikael Morin
2022-03-02 17:22                             ` [PATCH][v2] openmp, fortran: Check that the type of an event handle in a detach clause is suitable [PR104131] Kwok Cheung Yeung
2022-03-02 17:31                               ` Jakub Jelinek

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