re PR fortran/71894 ([OOP] ICE in gfc_add_component_ref, at fortran/class.c:227)
authorJanus Weil <janus@gcc.gnu.org>
Wed, 9 Nov 2016 09:22:52 +0000 (10:22 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Wed, 9 Nov 2016 09:22:52 +0000 (10:22 +0100)
2016-11-09  Janus Weil  <janus@gcc.gnu.org>

PR fortran/71894
* class.c (gfc_add_component_ref): Add safety checks to avoid ICE.

2016-11-09  Janus Weil  <janus@gcc.gnu.org>

PR fortran/71894
* gfortran.dg/class_59.f90: New test.

From-SVN: r241993

gcc/fortran/ChangeLog
gcc/fortran/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/class_59.f90 [new file with mode: 0644]

index 499c3d4c4e340d09ee3457bb1ad4769c46421354..6c39866487f8f614ff4c87face3ff0377607e8f4 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-09  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/71894
+       * class.c (gfc_add_component_ref): Add safety checks to avoid ICE.
+
 2016-11-08  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/68440
index 400c22abaf5795976f793043ea76a6d55860e358..b7f68d2f19a5240ebab4a2b5d935b64e59b2e3c7 100644 (file)
@@ -224,7 +224,8 @@ gfc_add_component_ref (gfc_expr *e, const char *name)
        break;
       tail = &((*tail)->next);
     }
-  if (derived->components->next->ts.type == BT_DERIVED &&
+  if (derived->components && derived->components->next &&
+      derived->components->next->ts.type == BT_DERIVED &&
       derived->components->next->ts.u.derived == NULL)
     {
       /* Fix up missing vtype.  */
index 888e9e2f6c07704268fcc646cf5ec1e72716d66f..43586a91430829ce733398d6efb8a7fe88755991 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-09  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/71894
+       * gfortran.dg/class_59.f90: New test.
+
 2016-11-09  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/78007
diff --git a/gcc/testsuite/gfortran.dg/class_59.f90 b/gcc/testsuite/gfortran.dg/class_59.f90
new file mode 100644 (file)
index 0000000..e077ef8
--- /dev/null
@@ -0,0 +1,25 @@
+! { dg-do compile }
+!
+! PR 71894: [OOP] ICE in gfc_add_component_ref, at fortran/class.c:227
+!
+! Contributed by Gerhard Steinmetz <gerhard.steinmetz.fortran@t-online.de>
+
+subroutine s1
+  type t
+    integer :: n
+  end type
+  type(t) :: x
+  class(t) :: y  ! { dg-error "must be dummy, allocatable or pointer" }
+  x = y
+end
+
+subroutine s2
+  type t
+  end type
+  class(t) :: x    ! { dg-error "must be dummy, allocatable or pointer" }
+  class(t), allocatable :: y
+  select type (y)
+  type is (t)
+    y = x
+  end select
+end