[Bug fortran/53643] [OOP] ICE (segfault) with INTENT(OUT) CLASS array

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jun 12 12:33:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53643

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-12 12:33:34 UTC ---
I am not sure whether the following (in trans-decl.c) is the proper fix or an
ugly work around, but it seems to work. -- Maybe, a proper fix would be to
modify the following "if" block in trans-array.c's structure_alloc_comps?

  if ((POINTER_TYPE_P (decl_type) && rank != 0)
        || (TREE_CODE (decl_type) == REFERENCE_TYPE && rank == 0))
    decl = build_fold_indirect_ref_loc (input_location,
                                    decl);

 * * *

The scalar coarray version does not seem to work; using an array coarray seems
to be okay. My impression is that structure_alloc_comps simply doesn't handle
coarrays types correctly. (Coarray components is a different issue and
currently not properly supported at all.) See trans-array.c part of the patch
below.

  type t
    integer, allocatable :: comp
  end type t
  contains
    subroutine foo(x)
      class(t), intent(out) :: x[*]
    end subroutine
  end


--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -3453,8 +3453,5 @@ init_intent_out_dt (gfc_symbol * proc_sym,
gfc_wrapped_block * block)
       {
-       tree decl = build_fold_indirect_ref_loc (input_location,
-                                                f->sym->backend_decl);
-       tmp = CLASS_DATA (f->sym)->backend_decl;
-       tmp = fold_build3_loc (input_location, COMPONENT_REF,
-                              TREE_TYPE (tmp), decl, tmp, NULL_TREE);
-       tmp = build_fold_indirect_ref_loc (input_location, tmp);
+       tmp = gfc_class_data_get (f->sym->backend_decl);
+       if (CLASS_DATA (f->sym)->as == NULL)
+         tmp = build_fold_indirect_ref_loc (input_location, tmp);
        tmp = gfc_deallocate_alloc_comp (CLASS_DATA (f->sym)->ts.u.derived,
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7320,5 +7320,3 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
        || (TREE_CODE (decl_type) == REFERENCE_TYPE && rank == 0))
-
-    decl = build_fold_indirect_ref_loc (input_location,
-                                   decl);
+    decl = build_fold_indirect_ref_loc (input_location, decl);

@@ -7330,3 +7328,3 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
   if (TREE_CODE (decl_type) == ARRAY_TYPE
-       || GFC_DESCRIPTOR_TYPE_P (decl_type))
+      || (GFC_DESCRIPTOR_TYPE_P (decl_type) && rank != 0))
     {



More information about the Gcc-bugs mailing list