re PR fortran/65795 (Segfault (invalid write) for ALLOCATE statement involving COARRAYS)
authorAndre Vehreschild <vehre@gcc.gnu.org>
Mon, 4 Apr 2016 09:32:28 +0000 (11:32 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Mon, 4 Apr 2016 09:32:28 +0000 (11:32 +0200)
gcc/fortran/ChangeLog:

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

PR fortran/65795
* trans-array.c (gfc_array_allocate): When the array is a coarray,
do not nullyfing its allocatable components in array_allocate, because
the nullify missed the array ref and nullifies the wrong component.
Cosmetics.

gcc/testsuite/ChangeLog:

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

PR fortran/65795
* gfortran.dg/coarray_allocate_6.f08: New test.

From-SVN: r234710

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

index 5ab7d3ff285368e11d50cd0801a7fffb7c84ec87..88ac1cc352ee60900d0594da79ce51b0cc0bf673 100644 (file)
@@ -1,3 +1,11 @@
+2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/65795
+       * trans-array.c (gfc_array_allocate): When the array is a coarray,
+       do not nullyfing its allocatable components in array_allocate, because
+       the nullify missed the array ref and nullifies the wrong component.
+       Cosmetics.
+
 2016-03-29  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/70397
index 649b80fec8473f7cff4b393cd7b7ea2c0d871026..825dfb822af5a963f0c76794432ff15dd80135d6 100644 (file)
@@ -5550,8 +5550,8 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
   else
       gfc_add_expr_to_block (&se->pre, set_descriptor);
 
-  if ((expr->ts.type == BT_DERIVED)
-       && expr->ts.u.derived->attr.alloc_comp)
+  if (expr->ts.type == BT_DERIVED && expr->ts.u.derived->attr.alloc_comp
+      && !coarray)
     {
       tmp = gfc_nullify_alloc_comp (expr->ts.u.derived, se->expr,
                                    ref->u.ar.as->rank);
index 43bad0faaa21337d82cd75e044e6f8fdfcad8eec..47656a92652cf0d36588986236272c3e50ed106a 100644 (file)
@@ -1,3 +1,8 @@
+2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/65795
+       * gfortran.dg/coarray_allocate_6.f08: New test.
+
 2016-04-04  Richard Biener  <rguenther@suse.de>
 
        PR rtl-optimization/70484
diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_6.f08 b/gcc/testsuite/gfortran.dg/coarray_allocate_6.f08
new file mode 100644 (file)
index 0000000..2fdd4c1
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do run }
+! { dg-options "-fcoarray=single -fdump-tree-original" }
+
+! Contributed by Tobias Burnus  <burnus@gcc.gnu.org>
+! Test fix for pr65795.
+
+implicit none
+
+type t2
+  integer, allocatable :: x
+end type t2
+
+type t3
+  type(t2), allocatable :: caf[:]
+end type t3
+
+!type(t3), save, target :: c, d
+type(t3), target :: c, d
+integer :: stat
+
+allocate(c%caf[*], stat=stat)
+end
+
+! Besides checking that the executable does not crash anymore, check
+! that the cause has been remove.
+! { dg-final { scan-tree-dump-not "c.caf.x = 0B" "original" } }
+