public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/105526 - [Coarray] Add missing checks for arguments of type TEAM_TYPE
@ 2022-05-09 20:20 Harald Anlauf
  2022-05-10 16:30 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-05-09 20:20 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

we were lacking checks for arguments of type TEAM_TYPE to some
coarray intrinsics (FORM TEAM, CHANGE TEAM, and SYNC TEAM).
The attached patch adds these, and as a bonus verifies that
TEAM NUMBER is a scalar integer.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-check-TEAM-arguments-to-coarray-intrinsics.patch --]
[-- Type: text/x-patch, Size: 3330 bytes --]

From 9e5aefa51df49a498854b25ce9dacd46bf58eb4e Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 9 May 2022 22:14:21 +0200
Subject: [PATCH] Fortran: check TEAM arguments to coarray intrinsics

TEAM arguments to coarray intrinsics must be scalar expressions of type
TEAM_TYPE of intrinsic module ISO_FORTRAN_ENV.

gcc/fortran/ChangeLog:

	PR fortran/105526
	* resolve.cc (check_team): New.
	(gfc_resolve_code): Add checks for arguments to coarray intrinsics
	FORM TEAM, CHANGE TEAM, and SYNC TEAM.

gcc/testsuite/ChangeLog:

	PR fortran/105526
	* gfortran.dg/coarray_50.f90: New test.
---
 gcc/fortran/resolve.cc                   | 32 ++++++++++++++++++++++++
 gcc/testsuite/gfortran.dg/coarray_50.f90 | 22 ++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/coarray_50.f90

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 29df531cdb6..c8335f939a9 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -11831,6 +11831,23 @@ deferred_op_assign (gfc_code **code, gfc_namespace *ns)
 }


+static bool
+check_team (gfc_expr *team, const char *intrinsic)
+{
+  if (team->rank != 0
+      || team->ts.type != BT_DERIVED
+      || team->ts.u.derived->from_intmod != INTMOD_ISO_FORTRAN_ENV
+      || team->ts.u.derived->intmod_sym_id != ISOFORTRAN_TEAM_TYPE)
+    {
+      gfc_error ("TEAM argument to %qs at %L must be a scalar expression "
+		 "of type TEAM_TYPE", intrinsic, &team->where);
+      return false;
+    }
+
+  return true;
+}
+
+
 /* Given a block of code, recursively resolve everything pointed to by this
    code block.  */

@@ -11999,10 +12016,25 @@ start:
 	  break;

 	case EXEC_FAIL_IMAGE:
+	  break;
+
 	case EXEC_FORM_TEAM:
+	  if (code->expr1 != NULL
+	      && (code->expr1->ts.type != BT_INTEGER || code->expr1->rank))
+	    gfc_error ("TEAM NUMBER argument to FORM TEAM at %L must be "
+		       "a scalar INTEGER", &code->expr1->where);
+	  check_team (code->expr2, "FORM TEAM");
+	  break;
+
 	case EXEC_CHANGE_TEAM:
+	  check_team (code->expr1, "CHANGE TEAM");
+	  break;
+
 	case EXEC_END_TEAM:
+	  break;
+
 	case EXEC_SYNC_TEAM:
+	  check_team (code->expr1, "SYNC TEAM");
 	  break;

 	case EXEC_ENTRY:
diff --git a/gcc/testsuite/gfortran.dg/coarray_50.f90 b/gcc/testsuite/gfortran.dg/coarray_50.f90
new file mode 100644
index 00000000000..e88d9d93f0e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_50.f90
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+!
+! PR fortran/105526 - check TEAM arguments to coarray intrinsics
+
+subroutine p
+  use iso_fortran_env, only: team_type
+  implicit none
+  type(team_type) :: team
+  type t
+     integer :: i
+  end type t
+  type(t) :: z
+  form team (0, team)
+  form team (0, 0)      ! { dg-error "scalar expression of type TEAM_TYPE" }
+  form team (0, [team]) ! { dg-error "scalar expression of type TEAM_TYPE" }
+  form team ([0], team) ! { dg-error "scalar INTEGER" }
+  form team (0., team)  ! { dg-error "scalar INTEGER" }
+  change team (0)       ! { dg-error "scalar expression of type TEAM_TYPE" }
+  end team
+  sync team (0)         ! { dg-error "scalar expression of type TEAM_TYPE" }
+end
--
2.35.3


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

* Re: [PATCH] PR fortran/105526 - [Coarray] Add missing checks for arguments of type TEAM_TYPE
  2022-05-09 20:20 [PATCH] PR fortran/105526 - [Coarray] Add missing checks for arguments of type TEAM_TYPE Harald Anlauf
@ 2022-05-10 16:30 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2022-05-10 16:30 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Le 09/05/2022 à 22:20, Harald Anlauf via Fortran a écrit :
> Dear Fortranners,
> 
> we were lacking checks for arguments of type TEAM_TYPE to some
> coarray intrinsics (FORM TEAM, CHANGE TEAM, and SYNC TEAM).
> The attached patch adds these, and as a bonus verifies that
> TEAM NUMBER is a scalar integer.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> 

OK, Thanks.

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

end of thread, other threads:[~2022-05-10 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 20:20 [PATCH] PR fortran/105526 - [Coarray] Add missing checks for arguments of type TEAM_TYPE Harald Anlauf
2022-05-10 16:30 ` Mikael Morin

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