re PR fortran/47463 ([OOP] ICE in gfc_add_component_ref)
authorJanus Weil <janus@gcc.gnu.org>
Mon, 31 Jan 2011 18:11:32 +0000 (19:11 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Mon, 31 Jan 2011 18:11:32 +0000 (19:11 +0100)
2011-01-31  Janus Weil  <janus@gcc.gnu.org>

PR fortran/47463
* resolve.c (resolve_typebound_subroutine): Bug fix for the case of
an argument of a typebound assignment being a component.

2011-01-31  Janus Weil  <janus@gcc.gnu.org>

PR fortran/47463
* gfortran.dg/typebound_assignment_1.f03: New.

From-SVN: r169443

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/typebound_assignment_1.f03 [new file with mode: 0644]

index f787a974c22ca4b85b98f1b1ad0c6d3f22d760e2..e146d761004f78ba08bad0c38db50d3165521955 100644 (file)
@@ -1,3 +1,9 @@
+2011-01-31  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/47463
+       * resolve.c (resolve_typebound_subroutine): Bug fix for the case of
+       an argument of a typebound assignment being a component.
+
 2011-01-31  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * gfortranspec.c (add_arg_libgfortran) [HAVE_LD_STATIC_DYNAMIC] Use
index 20be0d199d1722f6ea9c6a80441dc2a0faf2d41d..2a0fc49571c3bc55ddfca8d24e9b118716d44f6c 100644 (file)
@@ -5877,14 +5877,12 @@ resolve_typebound_subroutine (gfc_code *code)
 
   /* Deal with typebound operators for CLASS objects.  */
   expr = code->expr1->value.compcall.base_object;
-  if (expr && expr->symtree->n.sym->ts.type == BT_CLASS
-       && code->expr1->value.compcall.name)
+  if (expr && expr->ts.type == BT_CLASS && code->expr1->value.compcall.name)
     {
       /* Since the typebound operators are generic, we have to ensure
         that any delays in resolution are corrected and that the vtab
         is present.  */
-      ts = expr->symtree->n.sym->ts;
-      declared = ts.u.derived;
+      declared = expr->ts.u.derived;
       c = gfc_find_component (declared, "_vptr", true, true);
       if (c->ts.u.derived == NULL)
        c->ts.u.derived = gfc_find_derived_vtab (declared);
@@ -5895,6 +5893,7 @@ resolve_typebound_subroutine (gfc_code *code)
       /* Use the generic name if it is there.  */
       name = name ? name : code->expr1->value.function.esym->name;
       code->expr1->symtree = expr->symtree;
+      code->expr1->ref = gfc_copy_ref (expr->ref);
       expr->symtree->n.sym->ts.u.derived = declared;
       gfc_add_vptr_component (code->expr1);
       gfc_add_component_ref (code->expr1, name);
index 9f8550e03b5821050d6b2b8c55090a7d27dba6d0..0c17d83d189d5ea108d0618a66714efe3ff55a88 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-31  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/47463
+       * gfortran.dg/typebound_assignment_1.f03: New.
+
 2011-01-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/47538
diff --git a/gcc/testsuite/gfortran.dg/typebound_assignment_1.f03 b/gcc/testsuite/gfortran.dg/typebound_assignment_1.f03
new file mode 100644 (file)
index 0000000..359572b
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do compile }
+!
+! PR 47463: [OOP] ICE in gfc_add_component_ref
+!
+! Contributed by Rich Townsend <townsend@astro.wisc.edu>
+
+module hydro_state
+  type :: state_t
+   contains
+     procedure :: assign
+     generic   :: assignment(=) => assign
+  end type state_t
+contains
+  subroutine assign (this, that)
+    class(state_t), intent(inout) :: this
+    class(state_t), intent(in)    :: that
+  end subroutine assign
+end module hydro_state
+
+module hydro_flow
+  use hydro_state
+  type :: flow_t
+     class(state_t), allocatable :: st
+  end type flow_t
+contains
+  subroutine init_comps (this, st)
+    class(flow_t), intent(out) :: this
+    class(state_t), intent(in) :: st
+
+    allocate(state_t :: this%st)
+    this%st = st
+  end subroutine init_comps
+end module hydro_flow 
+
+! { dg-final { cleanup-modules "hydro_state hydro_flow" } }