re PR fortran/16400 (Invalid usage of assumed-size arrays is not rejected)
authorTobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>
Wed, 1 Sep 2004 21:07:39 +0000 (23:07 +0200)
committerTobias Schlüter <tobi@gcc.gnu.org>
Wed, 1 Sep 2004 21:07:39 +0000 (23:07 +0200)
fortran/
PR fortran/16400
PR fortran/16404
(port from g95)
* resolve.c (resolve_transfer): New function.
(resolve_code): Call resolve_transfer in case of EXEC_TRANSFER.

testsuite/
PR fortran/16404
* gfortran.dg/der_io_1.f90: XFAIL illegal testcase.

From-SVN: r86931

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/der_io_1.f90

index 7ec26200b624c5b86a601d233a7d78f1031ee58d..1c792b97a493bc8590594f4b3530ec107950b7f5 100644 (file)
@@ -1,3 +1,11 @@
+2004-09-01  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/16400
+       PR fortran/16404
+       (port from g95)
+       * resolve.c (resolve_transfer): New function.
+       (resolve_code): Call resolve_transfer in case of EXEC_TRANSFER.
+
 2004-08-31  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/16579
index e310f590236e6719aa8f72bba4c66856f3a65c8c..1a7fd80c2b303bf775370273d5146c03b7cad128 100644 (file)
@@ -2962,6 +2962,61 @@ resolve_select (gfc_code * code)
 }
 
 
+/* Resolve a transfer statement. This is making sure that:
+   -- a derived type being transferred has only non-pointer components
+   -- a derived type being transferred doesn't have private components
+   -- we're not trying to transfer a whole assumed size array.  */
+
+static void
+resolve_transfer (gfc_code * code)
+{
+  gfc_typespec *ts;
+  gfc_symbol *sym;
+  gfc_ref *ref;
+  gfc_expr *exp;
+
+  exp = code->expr;
+
+  if (exp->expr_type != EXPR_VARIABLE)
+    return;
+
+  sym = exp->symtree->n.sym;
+  ts = &sym->ts;
+
+  /* Go to actual component transferred.  */
+  for (ref = code->expr->ref; ref; ref = ref->next)
+    if (ref->type == REF_COMPONENT)
+      ts = &ref->u.c.component->ts;
+
+  if (ts->type == BT_DERIVED)
+    {
+      /* Check that transferred derived type doesn't contain POINTER
+        components.  */
+      if (derived_pointer (ts->derived))
+       {
+         gfc_error ("Data transfer element at %L cannot have "
+                    "POINTER components", &code->loc);
+         return;
+       }
+
+      if (ts->derived->component_access == ACCESS_PRIVATE)
+       {
+         gfc_error ("Data transfer element at %L cannot have "
+                    "PRIVATE components",&code->loc);
+         return;
+       }
+    }
+
+  if (sym->as != NULL && sym->as->type == AS_ASSUMED_SIZE
+      && exp->ref->type == REF_ARRAY && exp->ref->u.ar.type == AR_FULL)
+    {
+      gfc_error ("Data transfer element at %L cannot be a full reference to "
+                "an assumed-size array", &code->loc);
+      return;
+    }
+}
+
+
 /*********** Toplevel code resolution subroutines ***********/
 
 /* Given a branch to a label and a namespace, if the branch is conforming.
@@ -3568,7 +3623,6 @@ resolve_code (gfc_code * code, gfc_namespace * ns)
        case EXEC_EXIT:
        case EXEC_CONTINUE:
        case EXEC_DT_END:
-       case EXEC_TRANSFER:
        case EXEC_ENTRY:
          break;
 
@@ -3754,6 +3808,10 @@ resolve_code (gfc_code * code, gfc_namespace * ns)
          resolve_branch (code->ext.dt->eor, code);
          break;
 
+       case EXEC_TRANSFER:
+         resolve_transfer (code);
+         break;
+
        case EXEC_FORALL:
          resolve_forall_iterators (code->ext.forall_iterator);
 
index 5721b13429ff61f81fb769697bf5b335d984a186..ba2a71374773664b8108dcff620e981dc3a98d47 100644 (file)
@@ -1,3 +1,8 @@
+2004-09-01  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/16404
+       * gfortran.dg/der_io_1.f90: XFAIL illegal testcase.
+
 2004-09-01  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
        PR c/1522
index 8710bf81a73788d98d47a675bb7b83d1d3f163e5..4cbbf772cf60f3fe0bad26c0ed7de22ab895c784 100644 (file)
@@ -1,5 +1,6 @@
-! { dg-do run }
-! IO of derived types containing pointers
+! { dg-do compile }
+! PR 16404 Nr. 8
+! IO of derived types containing pointers is not allowed
 program der_io_1
   type t
     integer, pointer :: p
@@ -10,7 +11,7 @@ program der_io_1
 
   v%p => i
   i = 42
-  write (unit=s, fmt='(I2)') v
+  write (unit=s, fmt='(I2)') v ! { dg-error "POINTER components" "" }
   if (s .ne. '42') call abort ()
 end program