re PR fortran/71807 (Internal compiler error with NULL() reference in structure const...
authorAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 15 Jul 2016 09:28:47 +0000 (11:28 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 15 Jul 2016 09:28:47 +0000 (11:28 +0200)
gcc/fortran/ChangeLog:

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

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-15  Andre Vehreschild  <vehre@gcc.gnu.org>

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

From-SVN: r238368

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

index 594b19ec9a3321c15b4cecb65dd889fdc6f8f899..22ca4f4e48897f4f751163e121ef629da05791f4 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-15  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/71807
+       * trans-expr.c (gfc_trans_subcomponent_assign): Special casing
+       when allocatable component is set to null() in initializer.
+
 2016-07-14  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/29819
index 4321850b59d1de0c6ef36f0eb912880b12a0c073..e3559f4e00e8f22effde9d16438acff3205e288c 100644 (file)
@@ -7200,6 +7200,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 f31c63eac798b3a07c802751409aef865b6f9433..5ad50f944d8808d5f1e47100aea3f0e6c36b16b3 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-15  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/71807
+       * gfortran.dg/null_9.f90: New test.
+
 2016-07-15  Bin Cheng  <bin.cheng@arm.com>
 
        * gcc.dg/tree-ssa/loop-41.c: New test.
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
+