]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix check of polymorphic elements in data transfers [PR100971]
authorHarald Anlauf <anlauf@gmx.de>
Sun, 9 Oct 2022 18:43:32 +0000 (20:43 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 14 Oct 2022 20:16:57 +0000 (22:16 +0200)
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
gcc/testsuite/gfortran.dg/der_io_5.f90 [new file with mode: 0644]

index d133bc2d0340d1dd3617c51f647f915f303dde98..9202e2f10ad6d27bb90100fd0936523b98bf1d39 100644 (file)
@@ -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 (file)
index 0000000..193916c
--- /dev/null
@@ -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