public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran: fix check of polymorphic elements in data transfers [PR100971]
@ 2022-10-09 18:57 Harald Anlauf
  2022-10-14 19:38 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-10-09 18:57 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

the check of data transfer elements needs to verify that for
polymorphic objects there is a user defined DTIO procedure.
This check worked fine for scalars, but skipped arrays,
leading to an ICE later.

The obvious fix is to allow this check to inspect arrays.

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

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr100971.diff --]
[-- Type: text/x-patch, Size: 2489 bytes --]

From 4db0aba8309a2c7e2c7ac95195621dff02e9796c Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Sun, 9 Oct 2022 20:43:32 +0200
Subject: [PATCH] Fortran: fix check of polymorphic elements in data transfers
 [PR100971]

gcc/fortran/ChangeLog:

	PR fortran/100971
	* resolve.cc (resolve_transfer): Extend check for permissibility
	of polymorphic elements in a data transfer to arrays.

gcc/testsuite/ChangeLog:

	PR fortran/100971
	* gfortran.dg/der_io_5.f90: New test.
---
 gcc/fortran/resolve.cc                 |  5 +++++
 gcc/testsuite/gfortran.dg/der_io_5.f90 | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/der_io_5.f90

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index d133bc2d034..9202e2f10ad 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -10017,6 +10017,7 @@ resolve_transfer (gfc_code *code)

   if (exp == NULL || (exp->expr_type != EXPR_VARIABLE
 		      && exp->expr_type != EXPR_FUNCTION
+		      && exp->expr_type != EXPR_ARRAY
 		      && exp->expr_type != EXPR_STRUCTURE))
     return;

@@ -10030,6 +10031,7 @@ resolve_transfer (gfc_code *code)

   const gfc_typespec *ts = exp->expr_type == EXPR_STRUCTURE
 			|| exp->expr_type == EXPR_FUNCTION
+			|| exp->expr_type == EXPR_ARRAY
 			 ? &exp->ts : &exp->symtree->n.sym->ts;

   /* Go to actual component transferred.  */
@@ -10128,6 +10130,9 @@ resolve_transfer (gfc_code *code)
   if (exp->expr_type == EXPR_STRUCTURE)
     return;

+  if (exp->expr_type == EXPR_ARRAY)
+    return;
+
   sym = exp->symtree->n.sym;

   if (sym->as != NULL && sym->as->type == AS_ASSUMED_SIZE && exp->ref
diff --git a/gcc/testsuite/gfortran.dg/der_io_5.f90 b/gcc/testsuite/gfortran.dg/der_io_5.f90
new file mode 100644
index 00000000000..193916c4a65
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/der_io_5.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR fortran/100971 - ICE: Bad IO basetype (7)
+! Contributed by G.Steinmetz
+
+program p
+  implicit none
+  type t
+  end type
+  class(t), allocatable :: a, b(:)
+  type(t)               :: x, y(1)
+  integer               :: i
+  allocate (a,b(1))
+  print *, [a]            ! { dg-error "Data transfer element at .1. cannot be polymorphic" }
+  print *, [(b(i),i=1,1)] ! { dg-error "Data transfer element at .1. cannot be polymorphic" }
+  print *, [x]
+  print *, [(y(i),i=1,1)]
+end
--
2.35.3


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

* Re: [PATCH] Fortran: fix check of polymorphic elements in data transfers [PR100971]
  2022-10-09 18:57 [PATCH] Fortran: fix check of polymorphic elements in data transfers [PR100971] Harald Anlauf
@ 2022-10-14 19:38 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2022-10-14 19:38 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Le 09/10/2022 à 20:57, Harald Anlauf via Fortran a écrit :
> Dear all,
> 
> the check of data transfer elements needs to verify that for
> polymorphic objects there is a user defined DTIO procedure.
> This check worked fine for scalars, but skipped arrays,
> leading to an ICE later.
> 
> The obvious fix is to allow this check to inspect arrays.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> 
Yes, thanks.


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

end of thread, other threads:[~2022-10-14 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-09 18:57 [PATCH] Fortran: fix check of polymorphic elements in data transfers [PR100971] Harald Anlauf
2022-10-14 19:38 ` 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).