]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/71807 (Internal compiler error with NULL() reference in struc...
authorAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 22 Jul 2016 15:21:10 +0000 (17:21 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 22 Jul 2016 15:21:10 +0000 (17:21 +0200)
gcc/fortran/ChangeLog:

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

Backported from trunk:
PR fortran/71807
* trans-expr.c (gfc_trans_subcomponent_assign): Special casing
when allocatable component is set to null() in initializer.

gcc/testsuite/ChangeLog:

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

Backported from trunk:
PR fortran/71807
* gfortran.dg/null_9.f90: New test.

From-SVN: r238650

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/null_9.f90 [new file with mode: 0644]

index 69bae710ef7bee7e50fcd89efa67c0e8c9e79fdd..31986cf04729ddc0b2fa11d1e3ba746cee7e896d 100644 (file)
@@ -1,3 +1,10 @@
+2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       Backport from trunk:
+       PR fortran/71807
+       * trans-expr.c (gfc_trans_subcomponent_assign): Special casing
+       when allocatable component is set to null() in initializer.
+
 2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        Backport from trunk:
index 5e73115829fb58ecc4838af069c3569227d64a59..682fb0ec443430a26ed79e5336089014d8a1edc1 100644 (file)
@@ -7012,6 +7012,12 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * cm, gfc_expr * expr,
       tmp = gfc_trans_alloc_subarray_assign (tmp, cm, expr);
       gfc_add_expr_to_block (&block, tmp);
     }
+  else if (init && cm->attr.allocatable && expr->expr_type == EXPR_NULL)
+    {
+      /* NULL initialization for allocatable components.  */
+      gfc_add_modify (&block, dest, fold_convert (TREE_TYPE (dest),
+                                                 null_pointer_node));
+    }
   else if (init && (cm->attr.allocatable
           || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable
               && expr->ts.type != BT_CLASS)))
index 63a2e53c57517a45e2d5699c1c36285fd1c28170..1e991aeb0c39f60a991110a77b49cf6db4c0227d 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       Backport from trunk:
+       PR fortran/71807
+       * gfortran.dg/null_9.f90: New test.
+
 2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        Backport from trunk:
diff --git a/gcc/testsuite/gfortran.dg/null_9.f90 b/gcc/testsuite/gfortran.dg/null_9.f90
new file mode 100644 (file)
index 0000000..9afd938
--- /dev/null
@@ -0,0 +1,30 @@
+! { dg-do run }
+
+MODULE fold_convert_loc_ice
+  IMPLICIT NONE
+  PRIVATE
+
+  TYPE, PUBLIC :: ta
+    PRIVATE
+    INTEGER :: a_comp
+  END TYPE ta
+
+  TYPE, PUBLIC :: tb
+    TYPE(ta), ALLOCATABLE :: b_comp
+  END TYPE tb
+
+  PUBLIC :: proc
+CONTAINS
+  SUBROUTINE proc
+    TYPE(tb) :: b
+
+    b = tb(null())
+    if (allocated( b%b_comp )) call abort()
+  END SUBROUTINE proc
+END MODULE fold_convert_loc_ice
+
+  USE fold_convert_loc_ice
+
+  call proc()
+END
+