[Bug fortran/71862] ICE in gfc_add_component_ref, at fortran/class.c:241

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jul 13 19:21:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71862

--- Comment #2 from kargl at gcc dot gnu.org ---
(In reply to Gerhard Steinmetz from comment #0)
> Release versions (5, 6, 7) are bailed out, with no backtrace.
> Experimental versions (6, 7 tested) give a backtrace.
> 
> 
> $ cat z1.f90
> program p
>    type t
>       integer :: n = 0
>       integer, pointer :: q => null()
>    end type
>    type(t) :: x
>    print *, associated(x%q)
>    x = f()
>    print *, associated(x%q)
> contains
>    function f() result (z)
>       class(t) :: z
>       print *, associated(z%q)
>    end
> end
> 
> 
> 
> $ gfortran-6 z1.f90
> z1.f90:11:26:
> 
>     function f() result (z)
>                           1
> Error: CLASS variable 'z' at (1) must be dummy, allocatable or pointer
> (null):0: confused by earlier errors, bailing out
> 
> 
> 
> $ gfortran-7-20160710 z1.f90
> z1.f90:11:26:
> 
>     function f() result (z)
>                           1
> Error: CLASS variable 'z' at (1) must be dummy, allocatable or pointer

Index: resolve.c
===================================================================
--- resolve.c   (revision 238185)
+++ resolve.c   (working copy)
@@ -11440,8 +11440,9 @@ resolve_fl_var_and_proc (gfc_symbol *sym
         and excepted from the test.  */
       if (!sym->attr.class_ok && !sym->attr.use_assoc && !sym->assoc)
        {
-         gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
-                    "or pointer", sym->name, &sym->declared_at);
+         gfc_error ("CLASS variable %qs at %L shall be a dummy argument "
+                    "or have the POINTER or ALLOCATABLE attribute",
+                    sym->name, &sym->declared_at);
          return false;
        }
     }
Index: class.c
===================================================================
--- class.c     (revision 238185)
+++ class.c     (working copy)
@@ -238,12 +238,14 @@ gfc_add_component_ref (gfc_expr *e, cons
     /* Avoid losing memory.  */
     gfc_free_ref_list (*tail);
   c = gfc_find_component (derived, name, true, true, tail);
-  gcc_assert (c);
-  for (ref = *tail; ref->next; ref = ref->next)
-    ;
-  ref->next = next;
-  if (!next)
-    e->ts = c->ts;
+
+  if (c) {
+    for (ref = *tail; ref->next; ref = ref->next)
+      ;
+    ref->next = next;
+    if (!next)
+      e->ts = c->ts;
+  }
 }


More information about the Gcc-bugs mailing list