]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/67451 ([F08] ICE with sourced allocation from coarray.)
authorAndre Vehreschild <vehre@gcc.gnu.org>
Tue, 23 Feb 2016 10:29:26 +0000 (11:29 +0100)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Tue, 23 Feb 2016 10:29:26 +0000 (11:29 +0100)
gcc/testsuite/ChangeLog:

2016-02-23  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/67451
* gfortran.dg/coarray_allocate_5.f08: New test.

gcc/fortran/ChangeLog:

2016-02-23  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/67451
* trans-array.c (gfc_array_allocate): Take the attributes from the
expression to allocate and not from the source=-expression.

From-SVN: r233625

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/coarray_allocate_5.f08 [new file with mode: 0644]

index 99d13666804ba5065a646d0707be4e6a1827b290..7e0b8828e042a34d5f13a0d4795a26b2ea8d5cb5 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-23  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/67451
+       * trans-array.c (gfc_array_allocate): Take the attributes from the
+       expression to allocate and not from the source=-expression.
+
 2016-02-20  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/69423
index 2ff283312b6a7a880ead63baea927156a3becf9b..649b80fec8473f7cff4b393cd7b7ea2c0d871026 100644 (file)
@@ -5401,17 +5401,8 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
   if (!retrieve_last_ref (&ref, &prev_ref))
     return false;
 
-  if (ref->u.ar.type == AR_FULL && expr3 != NULL)
-    {
-      /* F08:C633: Array shape from expr3.  */
-      ref = expr3->ref;
-
-      /* Find the last reference in the chain.  */
-      if (!retrieve_last_ref (&ref, &prev_ref))
-       return false;
-      alloc_w_e3_arr_spec = true;
-    }
-
+  /* Take the allocatable and coarray properties solely from the expr-ref's
+     attributes and not from source=-expression.  */
   if (!prev_ref)
     {
       allocatable = expr->symtree->n.sym->attr.allocatable;
@@ -5428,6 +5419,17 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
   if (!dimension)
     gcc_assert (coarray);
 
+  if (ref->u.ar.type == AR_FULL && expr3 != NULL)
+    {
+      /* F08:C633: Array shape from expr3.  */
+      ref = expr3->ref;
+
+      /* Find the last reference in the chain.  */
+      if (!retrieve_last_ref (&ref, &prev_ref))
+       return false;
+      alloc_w_e3_arr_spec = true;
+    }
+
   /* Figure out the size of the array.  */
   switch (ref->u.ar.type)
     {
@@ -5463,7 +5465,8 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
   gfc_init_block (&set_descriptor_block);
   size = gfc_array_init_size (se->expr, alloc_w_e3_arr_spec ? expr->rank
                                                           : ref->u.ar.as->rank,
-                             ref->u.ar.as->corank, &offset, lower, upper,
+                             coarray ? ref->u.ar.as->corank : 0,
+                             &offset, lower, upper,
                              &se->pre, &set_descriptor_block, &overflow,
                              expr3_elem_size, nelems, expr3, e3_arr_desc,
                              e3_is_array_constr, expr);
index 1eacf121a450835108c41f7a269051111f0e0dc7..7d23225e994cfd06c6044e1fac66dd21721e5355 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-23  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/67451
+       * gfortran.dg/coarray_allocate_5.f08: New test.
+
 2016-02-23  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
 
        * gcc.target/s390/vcond-shift.c: Move to ...
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_5.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_5.f08
new file mode 100644 (file)
index 0000000..feb1bf3
--- /dev/null
@@ -0,0 +1,32 @@
+! { dg-do run }
+! { dg-options "-fcoarray=lib -lcaf_single -fdump-tree-original" }
+!
+! Contributed by Ian Harvey  <ian_harvey@bigpond.com>
+! Extended by Andre Vehreschild  <vehre@gcc.gnu.org>
+! to test that coarray references in allocate work now
+! PR fortran/67451
+
+  program main
+    implicit none
+    type foo
+      integer :: bar = 99
+    end type
+    class(foo), dimension(:), allocatable :: foobar[:]
+    class(foo), dimension(:), allocatable :: some_local_object
+    allocate(foobar(10)[*])
+
+    allocate(some_local_object, source=foobar)
+
+    if (.not. allocated(foobar)) call abort()
+    if (lbound(foobar, 1) /= 1 .OR. ubound(foobar, 1) /= 10) call abort()
+    if (.not. allocated(some_local_object)) call abort()
+    if (any(some_local_object(:)%bar /= [99, 99,  99, 99, 99, 99, 99, 99, 99, 99])) call abort()
+
+    deallocate(some_local_object)
+    deallocate(foobar)
+  end program
+
+! Check that some_local_object is treated as rank-1 array.
+! This failed beforehand, because the coarray attribute of the source=expression
+! was propagated to some_local_object in the allocate.
+! { dg-final { scan-tree-dump-not "some_local_object\._data\.dim\[1\]\.lbound" "original" } }