re PR fortran/57562 ([OOP] ICE due to extended derived type with PARAMETER attribute)
authorJanus Weil <janus@gcc.gnu.org>
Fri, 2 Jan 2015 16:31:52 +0000 (17:31 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Fri, 2 Jan 2015 16:31:52 +0000 (17:31 +0100)
2015-01-02  Janus Weil  <janus@gcc.gnu.org>

PR fortran/57562
* expr.c (find_component_ref): Deal with extended types.

2015-01-02  Janus Weil  <janus@gcc.gnu.org>

PR fortran/57562
* gfortran.dg/extends_16.f90: New.

From-SVN: r219144

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

index ea72687383f63db8481967d5eb5d78df0ea89277..9c88eb8ead69effddfe849764578ac7dafdfa5d9 100644 (file)
@@ -1,3 +1,8 @@
+2015-01-02  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/57562
+       * expr.c (find_component_ref): Deal with extended types.
+
 2015-01-02  Tobias Burnus  <burnus@net-b.de>
 
        * trans-decl.c (gfc_build_qualified_array): Fix coarray tokens
index 51f527dad122267606f2634d1fa3618a7651b598..2d85092865f37da45252d7c7860dff7fdb63118e 100644 (file)
@@ -1270,12 +1270,23 @@ depart:
 static gfc_constructor *
 find_component_ref (gfc_constructor_base base, gfc_ref *ref)
 {
-  gfc_component *comp;
-  gfc_component *pick;
+  gfc_component *pick = ref->u.c.component;
   gfc_constructor *c = gfc_constructor_first (base);
 
-  comp = ref->u.c.sym->components;
-  pick = ref->u.c.component;
+  gfc_symbol *dt = ref->u.c.sym;
+  int ext = dt->attr.extension;
+
+  /* For extended types, check if the desired component is in one of the
+   * parent types.  */
+  while (ext > 0 && gfc_find_component (dt->components->ts.u.derived,
+                                       pick->name, true, true))
+    {
+      dt = dt->components->ts.u.derived;
+      c = gfc_constructor_first (c->expr->value.constructor);
+      ext--;
+    }
+
+  gfc_component *comp = dt->components;
   while (comp != pick)
     {
       comp = comp->next;
index 095b09d80e37c9f284773c714ff797cf0cd5fb94..5fc092e9acf3ec67e1507fd4855d22a16849bd11 100644 (file)
@@ -1,3 +1,8 @@
+2015-01-02  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/57562
+       * gfortran.dg/extends_16.f90: New.
+
 2015-01-02  Tobias Burnus  <burnus@net-b.de>
 
        * gfortran.dg/coarray/caf.exp (dg-compile-aux-modules): Add.
@@ -12,7 +17,7 @@
 2015-01-02  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/60507
-       * gfortran.dg/dummy_procedure_11: New.
+       * gfortran.dg/dummy_procedure_11.f90: New.
 
 Copyright (C) 2015 Free Software Foundation, Inc.
 
diff --git a/gcc/testsuite/gfortran.dg/extends_16.f90 b/gcc/testsuite/gfortran.dg/extends_16.f90
new file mode 100644 (file)
index 0000000..376fcaa
--- /dev/null
@@ -0,0 +1,25 @@
+! { dg-do run }\r
+!\r
+! PR 57562: [OOP] ICE due to extended derived type with PARAMETER attribute\r
+!\r
+! Contributed by <helvio.vairinhos@gmail.com>\r
+\r
+   type :: Parent\r
+      integer :: member1 = 0\r
+   end type\r
+\r
+   type, extends(Parent) :: Child\r
+      integer :: member2 = 0\r
+   end type\r
+\r
+   type, extends(Child) :: Grandchild\r
+      integer :: member3 = 0\r
+   end type\r
+\r
+   type(Grandchild), parameter :: object = Grandchild(23, 42, -99)\r
+\r
+   if (object%member1 /= 23) call abort\r
+   if (object%member2 /= 42) call abort\r
+   if (object%member3 /= -99) call abort\r
+\r
+end\r