diff mbox

[Fortran] PR 51383 - fix ASSOCIATE with extended types

Message ID 4EDA74B2.9010909@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Dec. 3, 2011, 7:12 p.m. UTC
Another OOP-related patch: If one uses type extension, the first 
REF_COMPONENT does not necessarily refer directly to a component in the 
linked list starting at sym->ts.u.derived->components.

Using simply ref->u.c.component directly seems to work fine, thus, I do 
this with this patch.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias

PS: Other patches where review is pending:
- http://gcc.gnu.org/ml/fortran/2011-11/msg00250.html - no 
-fcheck=bounds for character(LEN=:) to avoid ICE
- http://gcc.gnu.org/ml/fortran/2011-11/msg00253.html - (Re)enable 
warning if a function result variable is not set [4.4-4.7 diagnostics 
regression]
- http://gcc.gnu.org/ml/fortran/2011-11/msg00254.html - Thomas' 
dependency-ICE patch [4.6/4.7 regression] (I will try to review this 
one, unless someone else is faster)

Comments

Mikael Morin Dec. 4, 2011, 4:11 p.m. UTC | #1
On Saturday 03 December 2011 20:12:50 Tobias Burnus wrote:
> Another OOP-related patch: If one uses type extension, the first
> REF_COMPONENT does not necessarily refer directly to a component in the
> linked list starting at sym->ts.u.derived->components.
> 
> Using simply ref->u.c.component directly seems to work fine, thus, I do
> this with this patch.
> 
> Build and regtested on x86-64-linux.
> OK for the trunk?
> 
OK, thanks

Mikael
diff mbox

Patch

2011-12-03  Tobias Burnus  <burnus@net-b.de>

	PR fortran/51383
	* resolve.c (find_array_spec): Use ref->u.c.component
	directly without starting from ts.u.derived.

2011-12-03  Tobias Burnus  <burnus@net-b.de>

	PR fortran/51383
	* gfortran.dg/associate_10.f90: New.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 181975)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -4515,14 +4515,12 @@  find_array_spec (gfc_expr *e)
 {
   gfc_array_spec *as;
   gfc_component *c;
-  gfc_symbol *derived;
   gfc_ref *ref;
 
   if (e->symtree->n.sym->ts.type == BT_CLASS)
     as = CLASS_DATA (e->symtree->n.sym)->as;
   else
     as = e->symtree->n.sym->as;
-  derived = NULL;
 
   for (ref = e->ref; ref; ref = ref->next)
     switch (ref->type)
@@ -4536,26 +4534,7 @@  find_array_spec (gfc_expr *e)
 	break;
 
       case REF_COMPONENT:
-	if (derived == NULL)
-	  derived = e->symtree->n.sym->ts.u.derived;
-
-	if (derived->attr.is_class)
-	  derived = derived->components->ts.u.derived;
-
-	c = derived->components;
-
-	for (; c; c = c->next)
-	  if (c == ref->u.c.component)
-	    {
-	      /* Track the sequence of component references.  */
-	      if (c->ts.type == BT_DERIVED)
-		derived = c->ts.u.derived;
-	      break;
-	    }
-
-	if (c == NULL)
-	  gfc_internal_error ("find_array_spec(): Component not found");
-
+	c = ref->u.c.component;
 	if (c->attr.dimension)
 	  {
 	    if (as != NULL)
Index: gcc/testsuite/gfortran.dg/associate_10.f90
===================================================================
--- gcc/testsuite/gfortran.dg/associate_10.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/associate_10.f90	(Arbeitskopie)
@@ -0,0 +1,23 @@ 
+! { dg-do compile }
+!
+! PR fortran/51383
+!
+! Contributed by kaiserkarl31@yahoo.com
+!
+! Was failing before at the ref resolution of y1(1)%i.
+!
+program extend
+   type :: a
+      integer :: i
+   end type a
+   type, extends (a) :: b
+      integer :: j
+   end type b
+   type (a) :: x(2)
+   type (b) :: y(2)
+   associate (x1 => x, y1 => y)
+      x1(1)%i = 1
+      ! Commenting out the following line will avoid the error
+      y1(1)%i = 2
+   end associate
+end program extend