public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
@ 2016-01-29 18:17 Andre Vehreschild
  2016-02-01 12:20 ` [Patch, fortran, pr67451, gcc-5, " Andre Vehreschild
  2016-02-02 18:24 ` [Patch, fortran, pr67451, " Paul Richard Thomas
  0 siblings, 2 replies; 11+ messages in thread
From: Andre Vehreschild @ 2016-01-29 18:17 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

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

Hi all,

attached is a patch to fix a regression in current gfortran when a
coarray is used in the source=-expression of an allocate(). The ICE was
caused by the class information, i.e., _vptr and so on, not at the
expected place. The patch fixes this.

The patch also fixes pr69418, which I will flag as a duplicate in a
second.

Bootstrapped and regtested ok on x86_64-linux-gnu/F23.

Ok for trunk?

Backport to gcc-5 is pending, albeit more difficult, because the
allocate() implementation on 5 is not as advanced the one in 6.

Regards,
	Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr67451_1.patch --]
[-- Type: text/x-patch, Size: 6147 bytes --]

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index c5ae4c5..8f63d34 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -1103,7 +1103,14 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems, bool unlimited)
 	}
       else
 	{
-	  from_data = gfc_class_data_get (from);
+	  /* Check that from is a class.  When the class is part of a coarray,
+	     then from is a common pointer and is to be used as is.  */
+	  tmp = POINTER_TYPE_P (TREE_TYPE (from))
+	      ? build_fold_indirect_ref (from) : from;
+	  from_data =
+	      (GFC_CLASS_TYPE_P (TREE_TYPE (tmp))
+	       || (DECL_P (tmp) && GFC_DECL_CLASS (tmp)))
+	      ? gfc_class_data_get (from) : from;
 	  is_from_desc = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (from_data));
 	}
      }
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 310d2cd..5143c31 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5358,7 +5358,8 @@ gfc_trans_allocate (gfc_code * code)
      expression.  */
   if (code->expr3)
     {
-      bool vtab_needed = false, temp_var_needed = false;
+      bool vtab_needed = false, temp_var_needed = false,
+	  is_coarray = gfc_is_coarray (code->expr3);
 
       /* Figure whether we need the vtab from expr3.  */
       for (al = code->ext.alloc.list; !vtab_needed && al != NULL;
@@ -5392,9 +5393,9 @@ gfc_trans_allocate (gfc_code * code)
 		     with the POINTER_PLUS_EXPR in this case.  */
 		  if (code->expr3->ts.type == BT_CLASS
 		      && TREE_CODE (se.expr) == NOP_EXPR
-		      && TREE_CODE (TREE_OPERAND (se.expr, 0))
-							   == POINTER_PLUS_EXPR)
-		      //&& ! GFC_CLASS_TYPE_P (TREE_TYPE (se.expr)))
+		      && (TREE_CODE (TREE_OPERAND (se.expr, 0))
+							    == POINTER_PLUS_EXPR
+			  || is_coarray))
 		    se.expr = TREE_OPERAND (se.expr, 0);
 		}
 	      /* Create a temp variable only for component refs to prevent
@@ -5435,7 +5436,7 @@ gfc_trans_allocate (gfc_code * code)
       if (se.expr != NULL_TREE && temp_var_needed)
 	{
 	  tree var, desc;
-	  tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) ?
+	  tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) || is_coarray ?
 		se.expr
 	      : build_fold_indirect_ref_loc (input_location, se.expr);
 
@@ -5448,7 +5449,7 @@ gfc_trans_allocate (gfc_code * code)
 	    {
 	      /* When an array_ref was in expr3, then the descriptor is the
 		 first operand.  */
-	      if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
+	      if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)) || is_coarray)
 		{
 		  desc = TREE_OPERAND (tmp, 0);
 		}
@@ -5460,11 +5461,12 @@ gfc_trans_allocate (gfc_code * code)
 	      e3_is = E3_DESC;
 	    }
 	  else
-	    desc = se.expr;
+	    desc = !is_coarray ? se.expr
+			       : TREE_OPERAND (TREE_OPERAND (se.expr, 0), 0);
 	  /* We need a regular (non-UID) symbol here, therefore give a
 	     prefix.  */
 	  var = gfc_create_var (TREE_TYPE (tmp), "source");
-	  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
+	  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)) || is_coarray)
 	    {
 	      gfc_allocate_lang_decl (var);
 	      GFC_DECL_SAVED_DESCRIPTOR (var) = desc;
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_2.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_2.f08
new file mode 100644
index 0000000..7a712a9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_2.f08
@@ -0,0 +1,26 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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), allocatable :: foobar[:]
+    class(foo), allocatable :: some_local_object
+    allocate(foobar[*])
+
+    allocate(some_local_object, source=foobar)
+
+    if (.not. allocated(foobar)) call abort()
+    if (.not. allocated(some_local_object)) call abort()
+
+    deallocate(some_local_object)
+    deallocate(foobar)
+  end program
+
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_3.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_3.f08
new file mode 100644
index 0000000..46f34c0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_3.f08
@@ -0,0 +1,28 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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
+
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_4.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_4.f08
new file mode 100644
index 0000000..a36d796
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_4.f08
@@ -0,0 +1,43 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! Contributed by Gerhard Steinmetz  <gerhard.steinmetz.fortran@t-online.de>
+!               Andre Vehreschild <vehre@gcc.gnu.org>
+! Check that PR fortran/69451 is fixed.
+
+program main
+
+implicit none
+
+type foo
+end type
+
+class(foo), allocatable :: p[:]
+class(foo), pointer :: r
+class(*), allocatable, target :: z
+
+allocate(p[*])
+
+call s(p, z)
+select type (z)
+  class is (foo) 
+        r => z
+  class default
+     call abort()
+end select
+
+if (.not. associated(r)) call abort()
+
+deallocate(r)
+deallocate(p)
+
+contains
+
+subroutine s(x, z) 
+   class(*) :: x[*]
+   class(*), allocatable:: z
+   allocate (z, source=x)
+end
+
+end
+

[-- Attachment #3: pr67451_1.txt --]
[-- Type: text/plain, Size: 618 bytes --]

gcc/testsuite/ChangeLog:

2016-01-29  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/67451
	PR fortran/69418
	* gfortran.dg/coarray_allocate_2.f08: New test.
	* gfortran.dg/coarray_allocate_3.f08: New test.
	* gfortran.dg/coarray_allocate_4.f08: New test.


gcc/fortran/ChangeLog:

2016-01-29  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/67451
	PR fortran/69418
	* trans-expr.c (gfc_copy_class_to_class): For coarrays just the
	pointer is passed.  Take it as is without trying to deref the
	_data component.
	* trans-stmt.c (gfc_trans_allocate): Take care of coarrays as
	argument to source=-expression.


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

* Re: [Patch, fortran, pr67451, gcc-5, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-01-29 18:17 [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray Andre Vehreschild
@ 2016-02-01 12:20 ` Andre Vehreschild
  2016-02-01 12:35   ` Andre Vehreschild
  2016-02-02 18:24 ` [Patch, fortran, pr67451, " Paul Richard Thomas
  1 sibling, 1 reply; 11+ messages in thread
From: Andre Vehreschild @ 2016-02-01 12:20 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

Hi all,

here is the backport of the patch for pr67451 for gcc-5. Because the
structure of the allocate() in trunk is quite different the patch looks
somewhat different, too, but essentially does the same.

Bootstrapped and regtests ok on x86_64-linux-gnu/F23.

Ok for gcc-5-branch?

Here is the link to the mainline patch:
https://gcc.gnu.org/ml/fortran/2016-01/msg00093.html

Regards,
	Andre

On Fri, 29 Jan 2016 19:17:24 +0100
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi all,
> 
> attached is a patch to fix a regression in current gfortran when a
> coarray is used in the source=-expression of an allocate(). The ICE was
> caused by the class information, i.e., _vptr and so on, not at the
> expected place. The patch fixes this.
> 
> The patch also fixes pr69418, which I will flag as a duplicate in a
> second.
> 
> Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> 
> Ok for trunk?
> 
> Backport to gcc-5 is pending, albeit more difficult, because the
> allocate() implementation on 5 is not as advanced the one in 6.
> 
> Regards,
> 	Andre


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

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

* Re: [Patch, fortran, pr67451, gcc-5, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-01 12:20 ` [Patch, fortran, pr67451, gcc-5, " Andre Vehreschild
@ 2016-02-01 12:35   ` Andre Vehreschild
  2016-02-02 18:44     ` Paul Richard Thomas
  0 siblings, 1 reply; 11+ messages in thread
From: Andre Vehreschild @ 2016-02-01 12:35 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

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

Oh, well, now with attachments. I am sorry.

- Andre

On Mon, 1 Feb 2016 13:20:24 +0100
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi all,
> 
> here is the backport of the patch for pr67451 for gcc-5. Because the
> structure of the allocate() in trunk is quite different the patch looks
> somewhat different, too, but essentially does the same.
> 
> Bootstrapped and regtests ok on x86_64-linux-gnu/F23.
> 
> Ok for gcc-5-branch?
> 
> Here is the link to the mainline patch:
> https://gcc.gnu.org/ml/fortran/2016-01/msg00093.html
> 
> Regards,
> 	Andre
> 
> On Fri, 29 Jan 2016 19:17:24 +0100
> Andre Vehreschild <vehre@gmx.de> wrote:
> 
> > Hi all,
> > 
> > attached is a patch to fix a regression in current gfortran when a
> > coarray is used in the source=-expression of an allocate(). The ICE was
> > caused by the class information, i.e., _vptr and so on, not at the
> > expected place. The patch fixes this.
> > 
> > The patch also fixes pr69418, which I will flag as a duplicate in a
> > second.
> > 
> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> > 
> > Ok for trunk?
> > 
> > Backport to gcc-5 is pending, albeit more difficult, because the
> > allocate() implementation on 5 is not as advanced the one in 6.
> > 
> > Regards,
> > 	Andre  
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr67451_v5_1.patch --]
[-- Type: text/x-patch, Size: 6534 bytes --]

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 4c368a8..0daa631 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -1019,6 +1019,7 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems, bool unlimited)
   tree fcn;
   tree fcn_type;
   tree from_data;
+  tree from_class_base = NULL;
   tree from_len;
   tree to_data;
   tree to_len;
@@ -1035,21 +1036,41 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems, bool unlimited)
   from_len = to_len = NULL_TREE;
 
   if (from != NULL_TREE)
-    fcn = gfc_class_vtab_copy_get (from);
+    {
+      /* Check that from is a class.  When the class is part of a coarray,
+	 then from is a common pointer and is to be used as is.  */
+      tmp = POINTER_TYPE_P (TREE_TYPE (from)) && !DECL_P (from)
+	  ? TREE_OPERAND (from, 0) : from;
+      if (GFC_CLASS_TYPE_P (TREE_TYPE (tmp))
+	  || (DECL_P (tmp) && GFC_DECL_CLASS (tmp)))
+	{
+	  from_class_base = from;
+	  from_data = gfc_class_data_get (from_class_base);
+	}
+      else
+	{
+	  /* For arrays two component_refs can be present.  */
+	  if (TREE_CODE (tmp) == COMPONENT_REF)
+	    tmp = TREE_OPERAND (tmp, 0);
+	  if (TREE_CODE (tmp) == COMPONENT_REF)
+	    tmp = TREE_OPERAND (tmp, 0);
+	  from_class_base = tmp;
+	  from_data = from;
+	}
+      fcn = gfc_class_vtab_copy_get (from_class_base);
+    }
   else
-    fcn = gfc_class_vtab_copy_get (to);
+    {
+      fcn = gfc_class_vtab_copy_get (to);
+      from_data = gfc_class_vtab_def_init_get (to);
+    }
 
   fcn_type = TREE_TYPE (TREE_TYPE (fcn));
 
-  if (from != NULL_TREE)
-      from_data = gfc_class_data_get (from);
-  else
-    from_data = gfc_class_vtab_def_init_get (to);
-
   if (unlimited)
     {
-      if (from != NULL_TREE && unlimited)
-	from_len = gfc_class_len_get (from);
+      if (from_class_base != NULL_TREE)
+	from_len = gfc_class_len_get (from_class_base);
       else
 	from_len = integer_zero_node;
     }
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 0be92cd..9c1f920 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5180,7 +5180,7 @@ gfc_trans_allocate (gfc_code * code)
      _vptr, _len and element_size for expr3.  */
   if (code->expr3)
     {
-      bool vtab_needed = false;
+      bool vtab_needed = false, is_coarray = gfc_is_coarray (code->expr3);
       /* expr3_tmp gets the tree when code->expr3.mold is set, i.e.,
 	 the expression is only needed to get the _vptr, _len a.s.o.  */
       tree expr3_tmp = NULL_TREE;
@@ -5245,7 +5245,8 @@ gfc_trans_allocate (gfc_code * code)
 		{
 		  tree var;
 
-		  tmp = build_fold_indirect_ref_loc (input_location,
+		  tmp = is_coarray ? se.expr
+				  : build_fold_indirect_ref_loc (input_location,
 						     se.expr);
 
 		  /* We need a regular (non-UID) symbol here, therefore give a
@@ -5297,6 +5298,16 @@ gfc_trans_allocate (gfc_code * code)
 	  else if (expr3_tmp != NULL_TREE
 		   && (VAR_P (expr3_tmp) ||!code->expr3->ref))
 	    tmp = gfc_class_vptr_get (expr3_tmp);
+	  else if (is_coarray && expr3 != NULL_TREE)
+	    {
+	      /* Get the ref to coarray's data.  May be wrapped in a
+		 NOP_EXPR.  */
+	      tmp = POINTER_TYPE_P (TREE_TYPE (expr3)) ? TREE_OPERAND (expr3, 0)
+						       : tmp;
+	      /* Get to the base variable, i.e., strip _data.data.  */
+	      tmp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 0);
+	      tmp = gfc_class_vptr_get (tmp);
+	    }
 	  else
 	    {
 	      rhs = gfc_find_and_cut_at_last_class_ref (code->expr3);
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_2.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_2.f08
new file mode 100644
index 0000000..7a712a9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_2.f08
@@ -0,0 +1,26 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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), allocatable :: foobar[:]
+    class(foo), allocatable :: some_local_object
+    allocate(foobar[*])
+
+    allocate(some_local_object, source=foobar)
+
+    if (.not. allocated(foobar)) call abort()
+    if (.not. allocated(some_local_object)) call abort()
+
+    deallocate(some_local_object)
+    deallocate(foobar)
+  end program
+
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_3.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_3.f08
new file mode 100644
index 0000000..b9413b6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_3.f08
@@ -0,0 +1,28 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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(10), 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
+
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_4.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_4.f08
new file mode 100644
index 0000000..a36d796
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_4.f08
@@ -0,0 +1,43 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! Contributed by Gerhard Steinmetz  <gerhard.steinmetz.fortran@t-online.de>
+!               Andre Vehreschild <vehre@gcc.gnu.org>
+! Check that PR fortran/69451 is fixed.
+
+program main
+
+implicit none
+
+type foo
+end type
+
+class(foo), allocatable :: p[:]
+class(foo), pointer :: r
+class(*), allocatable, target :: z
+
+allocate(p[*])
+
+call s(p, z)
+select type (z)
+  class is (foo) 
+        r => z
+  class default
+     call abort()
+end select
+
+if (.not. associated(r)) call abort()
+
+deallocate(r)
+deallocate(p)
+
+contains
+
+subroutine s(x, z) 
+   class(*) :: x[*]
+   class(*), allocatable:: z
+   allocate (z, source=x)
+end
+
+end
+

[-- Attachment #3: pr67451_v5_1.txt --]
[-- Type: text/plain, Size: 618 bytes --]

gcc/testsuite/ChangeLog:

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

	PR fortran/67451
	PR fortran/69418
	* gfortran.dg/coarray_allocate_2.f08: New test.
	* gfortran.dg/coarray_allocate_3.f08: New test.
	* gfortran.dg/coarray_allocate_4.f08: New test.


gcc/fortran/ChangeLog:

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

	PR fortran/67451
	PR fortran/69418
	* trans-expr.c (gfc_copy_class_to_class): For coarrays just the
	pointer is passed.  Take it as is without trying to deref the
	_data component.
	* trans-stmt.c (gfc_trans_allocate): Take care of coarrays as
	argument to source=-expression.


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

* Re: [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-01-29 18:17 [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray Andre Vehreschild
  2016-02-01 12:20 ` [Patch, fortran, pr67451, gcc-5, " Andre Vehreschild
@ 2016-02-02 18:24 ` Paul Richard Thomas
  2016-02-10 11:26   ` Andre Vehreschild
  1 sibling, 1 reply; 11+ messages in thread
From: Paul Richard Thomas @ 2016-02-02 18:24 UTC (permalink / raw)
  To: Andre Vehreschild; +Cc: GCC-Patches-ML, GCC-Fortran-ML

Hi Andre,

This looks to be OK for trunk.

I'll move to the 5-branch patch right away.

Thanks

Paul

On 29 January 2016 at 19:17, Andre Vehreschild <vehre@gmx.de> wrote:
> Hi all,
>
> attached is a patch to fix a regression in current gfortran when a
> coarray is used in the source=-expression of an allocate(). The ICE was
> caused by the class information, i.e., _vptr and so on, not at the
> expected place. The patch fixes this.
>
> The patch also fixes pr69418, which I will flag as a duplicate in a
> second.
>
> Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
>
> Ok for trunk?
>
> Backport to gcc-5 is pending, albeit more difficult, because the
> allocate() implementation on 5 is not as advanced the one in 6.
>
> Regards,
>         Andre
> --
> Andre Vehreschild * Email: vehre ad gmx dot de



-- 
The difference between genius and stupidity is; genius has its limits.

Albert Einstein

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

* Re: [Patch, fortran, pr67451, gcc-5, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-01 12:35   ` Andre Vehreschild
@ 2016-02-02 18:44     ` Paul Richard Thomas
  2016-02-03 10:39       ` Andre Vehreschild
  0 siblings, 1 reply; 11+ messages in thread
From: Paul Richard Thomas @ 2016-02-02 18:44 UTC (permalink / raw)
  To: Andre Vehreschild; +Cc: GCC-Patches-ML, GCC-Fortran-ML

Hi Andre,

This one looks good too. As every day goes by, I see more and more why
Tobias was so keen to incorporate all objects into a single descriptor
type :-)

OK for 5-branch.

Thanks for both the patches

Paul

On 1 February 2016 at 13:34, Andre Vehreschild <vehre@gmx.de> wrote:
> Oh, well, now with attachments. I am sorry.
>
> - Andre
>
> On Mon, 1 Feb 2016 13:20:24 +0100
> Andre Vehreschild <vehre@gmx.de> wrote:
>
>> Hi all,
>>
>> here is the backport of the patch for pr67451 for gcc-5. Because the
>> structure of the allocate() in trunk is quite different the patch looks
>> somewhat different, too, but essentially does the same.
>>
>> Bootstrapped and regtests ok on x86_64-linux-gnu/F23.
>>
>> Ok for gcc-5-branch?
>>
>> Here is the link to the mainline patch:
>> https://gcc.gnu.org/ml/fortran/2016-01/msg00093.html
>>
>> Regards,
>>       Andre
>>
>> On Fri, 29 Jan 2016 19:17:24 +0100
>> Andre Vehreschild <vehre@gmx.de> wrote:
>>
>> > Hi all,
>> >
>> > attached is a patch to fix a regression in current gfortran when a
>> > coarray is used in the source=-expression of an allocate(). The ICE was
>> > caused by the class information, i.e., _vptr and so on, not at the
>> > expected place. The patch fixes this.
>> >
>> > The patch also fixes pr69418, which I will flag as a duplicate in a
>> > second.
>> >
>> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
>> >
>> > Ok for trunk?
>> >
>> > Backport to gcc-5 is pending, albeit more difficult, because the
>> > allocate() implementation on 5 is not as advanced the one in 6.
>> >
>> > Regards,
>> >     Andre
>>
>>
>
>
> --
> Andre Vehreschild * Email: vehre ad gmx dot de



-- 
The difference between genius and stupidity is; genius has its limits.

Albert Einstein

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

* Re: [Patch, fortran, pr67451, gcc-5, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-02 18:44     ` Paul Richard Thomas
@ 2016-02-03 10:39       ` Andre Vehreschild
  0 siblings, 0 replies; 11+ messages in thread
From: Andre Vehreschild @ 2016-02-03 10:39 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: GCC-Patches-ML, GCC-Fortran-ML

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

Hi Paul,

thanks for the review. Committed as:

r233099 for ggc-5, and

r233101 for trunk.

Regards,
	Andre


On Tue, 2 Feb 2016 19:44:00 +0100
Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:

> Hi Andre,
> 
> This one looks good too. As every day goes by, I see more and more why
> Tobias was so keen to incorporate all objects into a single descriptor
> type :-)
> 
> OK for 5-branch.
> 
> Thanks for both the patches
> 
> Paul
> 
> On 1 February 2016 at 13:34, Andre Vehreschild <vehre@gmx.de> wrote:
> > Oh, well, now with attachments. I am sorry.
> >
> > - Andre
> >
> > On Mon, 1 Feb 2016 13:20:24 +0100
> > Andre Vehreschild <vehre@gmx.de> wrote:
> >  
> >> Hi all,
> >>
> >> here is the backport of the patch for pr67451 for gcc-5. Because the
> >> structure of the allocate() in trunk is quite different the patch looks
> >> somewhat different, too, but essentially does the same.
> >>
> >> Bootstrapped and regtests ok on x86_64-linux-gnu/F23.
> >>
> >> Ok for gcc-5-branch?
> >>
> >> Here is the link to the mainline patch:
> >> https://gcc.gnu.org/ml/fortran/2016-01/msg00093.html
> >>
> >> Regards,
> >>       Andre
> >>
> >> On Fri, 29 Jan 2016 19:17:24 +0100
> >> Andre Vehreschild <vehre@gmx.de> wrote:
> >>  
> >> > Hi all,
> >> >
> >> > attached is a patch to fix a regression in current gfortran when a
> >> > coarray is used in the source=-expression of an allocate(). The ICE was
> >> > caused by the class information, i.e., _vptr and so on, not at the
> >> > expected place. The patch fixes this.
> >> >
> >> > The patch also fixes pr69418, which I will flag as a duplicate in a
> >> > second.
> >> >
> >> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> >> >
> >> > Ok for trunk?
> >> >
> >> > Backport to gcc-5 is pending, albeit more difficult, because the
> >> > allocate() implementation on 5 is not as advanced the one in 6.
> >> >
> >> > Regards,
> >> >     Andre  
> >>
> >>  
> >
> >
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de  
> 
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: submit5.diff --]
[-- Type: text/x-patch, Size: 7590 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 233098)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,13 @@
+2016-02-03  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/67451
+	PR fortran/69418
+	* trans-expr.c (gfc_copy_class_to_class): For coarrays just the
+	pointer is passed.  Take it as is without trying to deref the
+	_data component.
+	* trans-stmt.c (gfc_trans_allocate): Take care of coarrays as
+	argument to source=-expression.
+
 2016-01-30  Bud Davis  <jmdavis@link.com>
 	    Mikael Morin  <mikael@gcc.gnu.org>
 
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(Revision 233098)
+++ gcc/fortran/trans-expr.c	(Arbeitskopie)
@@ -1019,6 +1019,7 @@
   tree fcn;
   tree fcn_type;
   tree from_data;
+  tree from_class_base = NULL;
   tree from_len;
   tree to_data;
   tree to_len;
@@ -1035,21 +1036,41 @@
   from_len = to_len = NULL_TREE;
 
   if (from != NULL_TREE)
-    fcn = gfc_class_vtab_copy_get (from);
+    {
+      /* Check that from is a class.  When the class is part of a coarray,
+	 then from is a common pointer and is to be used as is.  */
+      tmp = POINTER_TYPE_P (TREE_TYPE (from)) && !DECL_P (from)
+	  ? TREE_OPERAND (from, 0) : from;
+      if (GFC_CLASS_TYPE_P (TREE_TYPE (tmp))
+	  || (DECL_P (tmp) && GFC_DECL_CLASS (tmp)))
+	{
+	  from_class_base = from;
+	  from_data = gfc_class_data_get (from_class_base);
+	}
+      else
+	{
+	  /* For arrays two component_refs can be present.  */
+	  if (TREE_CODE (tmp) == COMPONENT_REF)
+	    tmp = TREE_OPERAND (tmp, 0);
+	  if (TREE_CODE (tmp) == COMPONENT_REF)
+	    tmp = TREE_OPERAND (tmp, 0);
+	  from_class_base = tmp;
+	  from_data = from;
+	}
+      fcn = gfc_class_vtab_copy_get (from_class_base);
+    }
   else
-    fcn = gfc_class_vtab_copy_get (to);
+    {
+      fcn = gfc_class_vtab_copy_get (to);
+      from_data = gfc_class_vtab_def_init_get (to);
+    }
 
   fcn_type = TREE_TYPE (TREE_TYPE (fcn));
 
-  if (from != NULL_TREE)
-      from_data = gfc_class_data_get (from);
-  else
-    from_data = gfc_class_vtab_def_init_get (to);
-
   if (unlimited)
     {
-      if (from != NULL_TREE && unlimited)
-	from_len = gfc_class_len_get (from);
+      if (from_class_base != NULL_TREE)
+	from_len = gfc_class_len_get (from_class_base);
       else
 	from_len = integer_zero_node;
     }
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 233098)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5180,7 +5180,7 @@
      _vptr, _len and element_size for expr3.  */
   if (code->expr3)
     {
-      bool vtab_needed = false;
+      bool vtab_needed = false, is_coarray = gfc_is_coarray (code->expr3);
       /* expr3_tmp gets the tree when code->expr3.mold is set, i.e.,
 	 the expression is only needed to get the _vptr, _len a.s.o.  */
       tree expr3_tmp = NULL_TREE;
@@ -5245,7 +5245,8 @@
 		{
 		  tree var;
 
-		  tmp = build_fold_indirect_ref_loc (input_location,
+		  tmp = is_coarray ? se.expr
+				  : build_fold_indirect_ref_loc (input_location,
 						     se.expr);
 
 		  /* We need a regular (non-UID) symbol here, therefore give a
@@ -5297,6 +5298,16 @@
 	  else if (expr3_tmp != NULL_TREE
 		   && (VAR_P (expr3_tmp) ||!code->expr3->ref))
 	    tmp = gfc_class_vptr_get (expr3_tmp);
+	  else if (is_coarray && expr3 != NULL_TREE)
+	    {
+	      /* Get the ref to coarray's data.  May be wrapped in a
+		 NOP_EXPR.  */
+	      tmp = POINTER_TYPE_P (TREE_TYPE (expr3)) ? TREE_OPERAND (expr3, 0)
+						       : tmp;
+	      /* Get to the base variable, i.e., strip _data.data.  */
+	      tmp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 0);
+	      tmp = gfc_class_vptr_get (tmp);
+	    }
 	  else
 	    {
 	      rhs = gfc_find_and_cut_at_last_class_ref (code->expr3);
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 233098)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,11 @@
+2016-02-03  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/67451
+	PR fortran/69418
+	* gfortran.dg/coarray_allocate_2.f08: New test.
+	* gfortran.dg/coarray_allocate_3.f08: New test.
+	* gfortran.dg/coarray_allocate_4.f08: New test.
+
 2016-02-02  Alan Modra  <amodra@gmail.com>
 
 	PR target/69548
Index: gcc/testsuite/gfortran.dg/coarray_allocate_2.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_2.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_2.f08	(Arbeitskopie)
@@ -0,0 +1,26 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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), allocatable :: foobar[:]
+    class(foo), allocatable :: some_local_object
+    allocate(foobar[*])
+
+    allocate(some_local_object, source=foobar)
+
+    if (.not. allocated(foobar)) call abort()
+    if (.not. allocated(some_local_object)) call abort()
+
+    deallocate(some_local_object)
+    deallocate(foobar)
+  end program
+
Index: gcc/testsuite/gfortran.dg/coarray_allocate_3.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_3.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_3.f08	(Arbeitskopie)
@@ -0,0 +1,28 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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(10), 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
+
Index: gcc/testsuite/gfortran.dg/coarray_allocate_4.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_4.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_4.f08	(Arbeitskopie)
@@ -0,0 +1,43 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! Contributed by Gerhard Steinmetz  <gerhard.steinmetz.fortran@t-online.de>
+!               Andre Vehreschild <vehre@gcc.gnu.org>
+! Check that PR fortran/69451 is fixed.
+
+program main
+
+implicit none
+
+type foo
+end type
+
+class(foo), allocatable :: p[:]
+class(foo), pointer :: r
+class(*), allocatable, target :: z
+
+allocate(p[*])
+
+call s(p, z)
+select type (z)
+  class is (foo) 
+        r => z
+  class default
+     call abort()
+end select
+
+if (.not. associated(r)) call abort()
+
+deallocate(r)
+deallocate(p)
+
+contains
+
+subroutine s(x, z) 
+   class(*) :: x[*]
+   class(*), allocatable:: z
+   allocate (z, source=x)
+end
+
+end
+

[-- Attachment #3: submit.diff --]
[-- Type: text/x-patch, Size: 7274 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 233100)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,13 @@
+2016-02-03  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/67451
+	PR fortran/69418
+	* trans-expr.c (gfc_copy_class_to_class): For coarrays just the
+	pointer is passed.  Take it as is without trying to deref the
+	_data component.
+	* trans-stmt.c (gfc_trans_allocate): Take care of coarrays as
+	argument to source=-expression.
+
 2016-02-02  Nathan Sidwell  <nathan@codesourcery.com>
 
 	* lang.opt (fopenacc-dim=): New option.
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(Revision 233100)
+++ gcc/fortran/trans-expr.c	(Arbeitskopie)
@@ -1103,7 +1103,14 @@
 	}
       else
 	{
-	  from_data = gfc_class_data_get (from);
+	  /* Check that from is a class.  When the class is part of a coarray,
+	     then from is a common pointer and is to be used as is.  */
+	  tmp = POINTER_TYPE_P (TREE_TYPE (from))
+	      ? build_fold_indirect_ref (from) : from;
+	  from_data =
+	      (GFC_CLASS_TYPE_P (TREE_TYPE (tmp))
+	       || (DECL_P (tmp) && GFC_DECL_CLASS (tmp)))
+	      ? gfc_class_data_get (from) : from;
 	  is_from_desc = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (from_data));
 	}
      }
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 233100)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5358,7 +5358,8 @@
      expression.  */
   if (code->expr3)
     {
-      bool vtab_needed = false, temp_var_needed = false;
+      bool vtab_needed = false, temp_var_needed = false,
+	  is_coarray = gfc_is_coarray (code->expr3);
 
       /* Figure whether we need the vtab from expr3.  */
       for (al = code->ext.alloc.list; !vtab_needed && al != NULL;
@@ -5392,9 +5393,9 @@
 		     with the POINTER_PLUS_EXPR in this case.  */
 		  if (code->expr3->ts.type == BT_CLASS
 		      && TREE_CODE (se.expr) == NOP_EXPR
-		      && TREE_CODE (TREE_OPERAND (se.expr, 0))
-							   == POINTER_PLUS_EXPR)
-		      //&& ! GFC_CLASS_TYPE_P (TREE_TYPE (se.expr)))
+		      && (TREE_CODE (TREE_OPERAND (se.expr, 0))
+							    == POINTER_PLUS_EXPR
+			  || is_coarray))
 		    se.expr = TREE_OPERAND (se.expr, 0);
 		}
 	      /* Create a temp variable only for component refs to prevent
@@ -5435,7 +5436,7 @@
       if (se.expr != NULL_TREE && temp_var_needed)
 	{
 	  tree var, desc;
-	  tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) ?
+	  tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) || is_coarray ?
 		se.expr
 	      : build_fold_indirect_ref_loc (input_location, se.expr);
 
@@ -5448,7 +5449,7 @@
 	    {
 	      /* When an array_ref was in expr3, then the descriptor is the
 		 first operand.  */
-	      if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
+	      if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)) || is_coarray)
 		{
 		  desc = TREE_OPERAND (tmp, 0);
 		}
@@ -5460,11 +5461,12 @@
 	      e3_is = E3_DESC;
 	    }
 	  else
-	    desc = se.expr;
+	    desc = !is_coarray ? se.expr
+			       : TREE_OPERAND (TREE_OPERAND (se.expr, 0), 0);
 	  /* We need a regular (non-UID) symbol here, therefore give a
 	     prefix.  */
 	  var = gfc_create_var (TREE_TYPE (tmp), "source");
-	  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
+	  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)) || is_coarray)
 	    {
 	      gfc_allocate_lang_decl (var);
 	      GFC_DECL_SAVED_DESCRIPTOR (var) = desc;
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 233100)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,11 @@
+2016-02-03  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/67451
+	PR fortran/69418
+	* gfortran.dg/coarray_allocate_2.f08: New test.
+	* gfortran.dg/coarray_allocate_3.f08: New test.
+	* gfortran.dg/coarray_allocate_4.f08: New test.
+
 2016-02-03  Alan Lawrence  <alan.lawrence@arm.com>
 
 	* gcc.dg/vect/vect-outer-1-big-array.c: Drop vect_multiple_sizes;
Index: gcc/testsuite/gfortran.dg/coarray_allocate_2.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_2.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_2.f08	(Arbeitskopie)
@@ -0,0 +1,26 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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), allocatable :: foobar[:]
+    class(foo), allocatable :: some_local_object
+    allocate(foobar[*])
+
+    allocate(some_local_object, source=foobar)
+
+    if (.not. allocated(foobar)) call abort()
+    if (.not. allocated(some_local_object)) call abort()
+
+    deallocate(some_local_object)
+    deallocate(foobar)
+  end program
+
Index: gcc/testsuite/gfortran.dg/coarray_allocate_3.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_3.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_3.f08	(Arbeitskopie)
@@ -0,0 +1,28 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! 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
+
Index: gcc/testsuite/gfortran.dg/coarray_allocate_4.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_4.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_4.f08	(Arbeitskopie)
@@ -0,0 +1,43 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single" }
+!
+! Contributed by Gerhard Steinmetz  <gerhard.steinmetz.fortran@t-online.de>
+!               Andre Vehreschild <vehre@gcc.gnu.org>
+! Check that PR fortran/69451 is fixed.
+
+program main
+
+implicit none
+
+type foo
+end type
+
+class(foo), allocatable :: p[:]
+class(foo), pointer :: r
+class(*), allocatable, target :: z
+
+allocate(p[*])
+
+call s(p, z)
+select type (z)
+  class is (foo) 
+        r => z
+  class default
+     call abort()
+end select
+
+if (.not. associated(r)) call abort()
+
+deallocate(r)
+deallocate(p)
+
+contains
+
+subroutine s(x, z) 
+   class(*) :: x[*]
+   class(*), allocatable:: z
+   allocate (z, source=x)
+end
+
+end
+

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

* Re: [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-02 18:24 ` [Patch, fortran, pr67451, " Paul Richard Thomas
@ 2016-02-10 11:26   ` Andre Vehreschild
  2016-02-17  9:17     ` [PING, Patch, " Andre Vehreschild
  2016-02-17 13:13     ` [Patch, " Paul Richard Thomas
  0 siblings, 2 replies; 11+ messages in thread
From: Andre Vehreschild @ 2016-02-10 11:26 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: GCC-Patches-ML, GCC-Fortran-ML

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

Hi all,

unfortunately was my last patch for pr67451 not perfect and introduced
regressions occurring on s390(x) and with the sanitizer. These were
caused, because when taking the array specs from the source=-expression
also its attributes, like coarray state and so on where taken from
there. This additionally added a corank to local objects to allocate,
that were no coarrays overwriting data in the array handle. The attached
patch fixes both issues.

The patch for gcc-5 is not affected, because in gcc-5 the feature of
taking the array spec from the source=-expression is not implemented.

Bootstrapped and regtested ok on x86_64-linux-gnu/F23.

Ok for trunk?

Regards,
	Andre

On Tue, 2 Feb 2016 19:24:46 +0100
Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:

> Hi Andre,
> 
> This looks to be OK for trunk.
> 
> I'll move to the 5-branch patch right away.
> 
> Thanks
> 
> Paul
> 
> On 29 January 2016 at 19:17, Andre Vehreschild <vehre@gmx.de> wrote:
> > Hi all,
> >
> > attached is a patch to fix a regression in current gfortran when a
> > coarray is used in the source=-expression of an allocate(). The ICE was
> > caused by the class information, i.e., _vptr and so on, not at the
> > expected place. The patch fixes this.
> >
> > The patch also fixes pr69418, which I will flag as a duplicate in a
> > second.
> >
> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> >
> > Ok for trunk?
> >
> > Backport to gcc-5 is pending, albeit more difficult, because the
> > allocate() implementation on 5 is not as advanced the one in 6.
> >
> > Regards,
> >         Andre
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de  
> 
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr67451_v6_2.patch --]
[-- Type: text/x-patch, Size: 3342 bytes --]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 2ff2833..649b80f 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -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);
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_5.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_5.f08
new file mode 100644
index 0000000..feb1bf3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_allocate_5.f08
@@ -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" } }

[-- Attachment #3: pr67451_v6_2.txt --]
[-- Type: text/plain, Size: 371 bytes --]

gcc/testsuite/ChangeLog:

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

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


gcc/fortran/ChangeLog:

2016-02-10  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.


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

* Re: [PING, Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-10 11:26   ` Andre Vehreschild
@ 2016-02-17  9:17     ` Andre Vehreschild
  2016-02-17 13:13     ` [Patch, " Paul Richard Thomas
  1 sibling, 0 replies; 11+ messages in thread
From: Andre Vehreschild @ 2016-02-17  9:17 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: GCC-Patches-ML, GCC-Fortran-ML

PING !

On Wed, 10 Feb 2016 12:26:24 +0100
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi all,
> 
> unfortunately was my last patch for pr67451 not perfect and introduced
> regressions occurring on s390(x) and with the sanitizer. These were
> caused, because when taking the array specs from the source=-expression
> also its attributes, like coarray state and so on where taken from
> there. This additionally added a corank to local objects to allocate,
> that were no coarrays overwriting data in the array handle. The attached
> patch fixes both issues.
> 
> The patch for gcc-5 is not affected, because in gcc-5 the feature of
> taking the array spec from the source=-expression is not implemented.
> 
> Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> 
> Ok for trunk?
> 
> Regards,
> 	Andre
> 
> On Tue, 2 Feb 2016 19:24:46 +0100
> Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:
> 
> > Hi Andre,
> > 
> > This looks to be OK for trunk.
> > 
> > I'll move to the 5-branch patch right away.
> > 
> > Thanks
> > 
> > Paul
> > 
> > On 29 January 2016 at 19:17, Andre Vehreschild <vehre@gmx.de> wrote:  
> > > Hi all,
> > >
> > > attached is a patch to fix a regression in current gfortran when a
> > > coarray is used in the source=-expression of an allocate(). The ICE was
> > > caused by the class information, i.e., _vptr and so on, not at the
> > > expected place. The patch fixes this.
> > >
> > > The patch also fixes pr69418, which I will flag as a duplicate in a
> > > second.
> > >
> > > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> > >
> > > Ok for trunk?
> > >
> > > Backport to gcc-5 is pending, albeit more difficult, because the
> > > allocate() implementation on 5 is not as advanced the one in 6.
> > >
> > > Regards,
> > >         Andre
> > > --
> > > Andre Vehreschild * Email: vehre ad gmx dot de    
> > 
> > 
> >   
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

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

* Re: [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-10 11:26   ` Andre Vehreschild
  2016-02-17  9:17     ` [PING, Patch, " Andre Vehreschild
@ 2016-02-17 13:13     ` Paul Richard Thomas
  2016-02-23 10:30       ` Andre Vehreschild
  1 sibling, 1 reply; 11+ messages in thread
From: Paul Richard Thomas @ 2016-02-17 13:13 UTC (permalink / raw)
  To: Andre Vehreschild; +Cc: GCC-Patches-ML, GCC-Fortran-ML

Dear Andre,

I had left this to somebody else, since I am travelling!

The patch is verging on 'obvious' and so it is OK for trunk.

Could you check the line terminators please? I am seeing CR-LFs but
this might be an effect of transmission.

Thanks for the patch.

Paul

On 10 February 2016 at 12:26, Andre Vehreschild <vehre@gmx.de> wrote:
> Hi all,
>
> unfortunately was my last patch for pr67451 not perfect and introduced
> regressions occurring on s390(x) and with the sanitizer. These were
> caused, because when taking the array specs from the source=-expression
> also its attributes, like coarray state and so on where taken from
> there. This additionally added a corank to local objects to allocate,
> that were no coarrays overwriting data in the array handle. The attached
> patch fixes both issues.
>
> The patch for gcc-5 is not affected, because in gcc-5 the feature of
> taking the array spec from the source=-expression is not implemented.
>
> Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
>
> Ok for trunk?
>
> Regards,
>         Andre
>
> On Tue, 2 Feb 2016 19:24:46 +0100
> Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:
>
>> Hi Andre,
>>
>> This looks to be OK for trunk.
>>
>> I'll move to the 5-branch patch right away.
>>
>> Thanks
>>
>> Paul
>>
>> On 29 January 2016 at 19:17, Andre Vehreschild <vehre@gmx.de> wrote:
>> > Hi all,
>> >
>> > attached is a patch to fix a regression in current gfortran when a
>> > coarray is used in the source=-expression of an allocate(). The ICE was
>> > caused by the class information, i.e., _vptr and so on, not at the
>> > expected place. The patch fixes this.
>> >
>> > The patch also fixes pr69418, which I will flag as a duplicate in a
>> > second.
>> >
>> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
>> >
>> > Ok for trunk?
>> >
>> > Backport to gcc-5 is pending, albeit more difficult, because the
>> > allocate() implementation on 5 is not as advanced the one in 6.
>> >
>> > Regards,
>> >         Andre
>> > --
>> > Andre Vehreschild * Email: vehre ad gmx dot de
>>
>>
>>
>
>
> --
> Andre Vehreschild * Email: vehre ad gmx dot de



-- 
The difference between genius and stupidity is; genius has its limits.

Albert Einstein

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

* Re: [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
  2016-02-17 13:13     ` [Patch, " Paul Richard Thomas
@ 2016-02-23 10:30       ` Andre Vehreschild
  0 siblings, 0 replies; 11+ messages in thread
From: Andre Vehreschild @ 2016-02-23 10:30 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: GCC-Patches-ML, GCC-Fortran-ML

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

Hi Paul,

thanks for the review. Committed as r233625.

Regards,
	Andre

On Wed, 17 Feb 2016 14:13:48 +0100
Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:

> Dear Andre,
> 
> I had left this to somebody else, since I am travelling!
> 
> The patch is verging on 'obvious' and so it is OK for trunk.
> 
> Could you check the line terminators please? I am seeing CR-LFs but
> this might be an effect of transmission.
> 
> Thanks for the patch.
> 
> Paul
> 
> On 10 February 2016 at 12:26, Andre Vehreschild <vehre@gmx.de> wrote:
> > Hi all,
> >
> > unfortunately was my last patch for pr67451 not perfect and introduced
> > regressions occurring on s390(x) and with the sanitizer. These were
> > caused, because when taking the array specs from the source=-expression
> > also its attributes, like coarray state and so on where taken from
> > there. This additionally added a corank to local objects to allocate,
> > that were no coarrays overwriting data in the array handle. The attached
> > patch fixes both issues.
> >
> > The patch for gcc-5 is not affected, because in gcc-5 the feature of
> > taking the array spec from the source=-expression is not implemented.
> >
> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> >
> > Ok for trunk?
> >
> > Regards,
> >         Andre
> >
> > On Tue, 2 Feb 2016 19:24:46 +0100
> > Paul Richard Thomas <paul.richard.thomas@gmail.com> wrote:
> >  
> >> Hi Andre,
> >>
> >> This looks to be OK for trunk.
> >>
> >> I'll move to the 5-branch patch right away.
> >>
> >> Thanks
> >>
> >> Paul
> >>
> >> On 29 January 2016 at 19:17, Andre Vehreschild <vehre@gmx.de> wrote:  
> >> > Hi all,
> >> >
> >> > attached is a patch to fix a regression in current gfortran when a
> >> > coarray is used in the source=-expression of an allocate(). The ICE was
> >> > caused by the class information, i.e., _vptr and so on, not at the
> >> > expected place. The patch fixes this.
> >> >
> >> > The patch also fixes pr69418, which I will flag as a duplicate in a
> >> > second.
> >> >
> >> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
> >> >
> >> > Ok for trunk?
> >> >
> >> > Backport to gcc-5 is pending, albeit more difficult, because the
> >> > allocate() implementation on 5 is not as advanced the one in 6.
> >> >
> >> > Regards,
> >> >         Andre
> >> > --
> >> > Andre Vehreschild * Email: vehre ad gmx dot de  
> >>
> >>
> >>  
> >
> >
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de  
> 
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 4091 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 233624)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -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: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(Revision 233624)
+++ gcc/fortran/trans-array.c	(Arbeitskopie)
@@ -5401,17 +5401,8 @@
   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 @@
   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_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: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 233624)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -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 ...
Index: gcc/testsuite/gfortran.dg/coarray_allocate_5.f08
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_allocate_5.f08	(nicht existent)
+++ gcc/testsuite/gfortran.dg/coarray_allocate_5.f08	(Arbeitskopie)
@@ -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" } }

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

* Re: [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray
@ 2016-02-10 16:48 Dominique d'Humières
  0 siblings, 0 replies; 11+ messages in thread
From: Dominique d'Humières @ 2016-02-10 16:48 UTC (permalink / raw)
  To: Andre Vehreschild; +Cc: Paul Richard Thomas, fortran, gcc-patches

> Hi all,
> 
> unfortunately was my last patch for pr67451 not perfect and introduced
> regressions occurring on s390(x) and with the sanitizer.  These were
> caused, because when taking the array specs from the source=-expression
> also its attributes, like coarray state and so on where taken from there.
> This additionally added a crank to local objects to allocate, that were
> no coarrays overwriting data in the array handle.  The attached patch
> fixes both issues.
>
> The patch for gcc-5 is not affected, because in gcc-5 the feature of
> taking the array spec from the source=-expression is not implemented.
>
> Bootstrapped and regtested ok on x86_64-linux-gnu/F23.
>
>  Ok for trunk?
>
> Regards,
> Andre

The patch fixes the two issues I saw on x86_64-apple-darwin15.

Thanks.

Dominique

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

end of thread, other threads:[~2016-02-23 10:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-29 18:17 [Patch, fortran, pr67451, v1] [5/6 Regression] ICE with sourced allocation from coarray Andre Vehreschild
2016-02-01 12:20 ` [Patch, fortran, pr67451, gcc-5, " Andre Vehreschild
2016-02-01 12:35   ` Andre Vehreschild
2016-02-02 18:44     ` Paul Richard Thomas
2016-02-03 10:39       ` Andre Vehreschild
2016-02-02 18:24 ` [Patch, fortran, pr67451, " Paul Richard Thomas
2016-02-10 11:26   ` Andre Vehreschild
2016-02-17  9:17     ` [PING, Patch, " Andre Vehreschild
2016-02-17 13:13     ` [Patch, " Paul Richard Thomas
2016-02-23 10:30       ` Andre Vehreschild
2016-02-10 16:48 Dominique d'Humières

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