Fix ICE in gfc_trans_subcomponent_assign due to NULL components.
authorFritz O. Reese <fritzoreese@gmail.com>
Wed, 9 Nov 2016 17:31:27 +0000 (17:31 +0000)
committerFritz Reese <foreese@gcc.gnu.org>
Wed, 9 Nov 2016 17:31:27 +0000 (17:31 +0000)
PR fortran/78259
* gcc/fortran/trans-expr.c (gfc_trans_subcomponent_assign): Guard
against NULL values.

PR fortran/78259
* gcc/testsuite/gfortran.dg/pr78259.f90: New test.

From-SVN: r242010

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

index 615ade012f7911f69c170ad4d341084207d05806..ab59584852c7cad3863481b88016c8551df0f820 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-09  Fritz O. Reese <fritzoreese@gmail.com>
+
+       PR fortran/78259
+       * trans-expr.c (gfc_trans_subcomponent_assign): Guard against NULL
+       values.
+
 2016-11-09  Steve Kargl <kargl@gcc.gnu.org>
            Janus Weil  <janus@gcc.gnu.org>
 
index 61214295f664e7cd8e2a9ffcdc47628d7805008b..48296b8dbdb36efef36dbf4e1e1dfe95b7950474 100644 (file)
@@ -7327,7 +7327,8 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * cm, gfc_expr * expr,
       gfc_constructor *c = gfc_constructor_first (expr->value.constructor);
       /* We mark that the entire union should be initialized with a contrived
          EXPR_NULL expression at the beginning.  */
-      if (c->n.component == NULL && c->expr->expr_type == EXPR_NULL)
+      if (c != NULL && c->n.component == NULL
+         && c->expr != NULL && c->expr->expr_type == EXPR_NULL)
         {
           tmp = build2_loc (input_location, MODIFY_EXPR, void_type_node,
                            dest, build_constructor (TREE_TYPE (dest), NULL));
index 749c7d6bef0672e6fa58fabef247dfb3fe9d477b..7def8a781cdc863d2387f5a32419b88c0eca8518 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-09  Fritz O. Reese <fritzoreese@gmail.com>
+
+       PR fortran/78259
+       * gfortran.dg/pr78259.f90: New test.
+
 2016-11-09  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/60777
diff --git a/gcc/testsuite/gfortran.dg/pr78259.f90 b/gcc/testsuite/gfortran.dg/pr78259.f90
new file mode 100644 (file)
index 0000000..82f48ea
--- /dev/null
@@ -0,0 +1,22 @@
+! { dg-do "compile" }
+! { dg-options "-fdec-structure" }
+!
+! PR fortran/78259
+!
+! ICE in gfc_trans_subcomponent_assign
+!
+
+subroutine sub
+  structure /s/
+    union
+      map
+        integer n(2)
+      end map
+      map
+        integer(8) m /2/
+      end map
+    end union
+  end structure
+  record /s/ r
+  r.n(1) = 1
+end