diff mbox series

[fortran] PR69654 - ICE in gfc_trans_structure_assign

Message ID CAGkQGiL3j9zr9okGW4VVArZH_fXXzuimSdgHonZ+4BgHVEO0jA@mail.gmail.com
State New
Headers show
Series [fortran] PR69654 - ICE in gfc_trans_structure_assign | expand

Commit Message

Paul Richard Thomas Nov. 14, 2019, 3:52 p.m. UTC
As I remarked in PR, this fix probably comes 1,379 days too late. I am
not at all sure that I understand why I couldn't see the problem
because it is rather trivial.

I am open to not adding the second gcc_assert - it does seem like overkill.

Regtested on FC30/x86_64 - OK for trunk and ....?

Paul

2019-11-14  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/69654
    * trans-expr.c (gfc_trans_structure_assign): Move assignment to
    'cm' after treatment of C pointer types and test that the type
    has been completely built before it. Add an assert that the
    backend_decl for each component exists.

2019-11-14  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/69654
    * gfortran.dg/derived_init_6.f90: New test.

Comments

Steve Kargl Nov. 14, 2019, 5 p.m. UTC | #1
On Thu, Nov 14, 2019 at 03:52:26PM +0000, Paul Richard Thomas wrote:
> As I remarked in PR, this fix probably comes 1,379 days too late. I am
> not at all sure that I understand why I couldn't see the problem
> because it is rather trivial.
> 
> I am open to not adding the second gcc_assert - it does seem like overkill.
> 
> Regtested on FC30/x86_64 - OK for trunk and ....?
> 

Yes.  7-branch is now closed.  So, if you're inclined
to backport then it is also ok for 8 and 9 branches
after testing.
diff mbox series

Patch

Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 278024)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_trans_structure_assign (tree dest, g
*** 8327,8333 ****
    gfc_se se;

    gfc_start_block (&block);
-   cm = expr->ts.u.derived->components;

    if (expr->ts.u.derived->from_intmod == INTMOD_ISO_C_BINDING
        && (expr->ts.u.derived->intmod_sym_id == ISOCBINDING_PTR
--- 8327,8332 ----
*************** gfc_trans_structure_assign (tree dest, g
*** 8345,8350 ****
--- 8344,8360 ----
        return gfc_finish_block (&block);
      }

+   /* Make sure that the derived type has been completely built.  */
+   if (!expr->ts.u.derived->backend_decl
+       || !TYPE_FIELDS (expr->ts.u.derived->backend_decl))
+     {
+       tmp = gfc_typenode_for_spec (&expr->ts);
+       gcc_assert (tmp);
+     }
+
+   cm = expr->ts.u.derived->components;
+
+
    if (coarray)
      gfc_init_se (&se, NULL);

*************** gfc_trans_structure_assign (tree dest, g
*** 8415,8420 ****
--- 8425,8431 ----
  	  gfc_add_expr_to_block (&block, tmp);
  	}
        field = cm->backend_decl;
+       gcc_assert(field);
        tmp = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
  			     dest, field, NULL_TREE);
        if (!c->expr)
Index: gcc/testsuite/gfortran.dg/derived_init_6.f90
===================================================================
*** gcc/testsuite/gfortran.dg/derived_init_6.f90	(nonexistent)
--- gcc/testsuite/gfortran.dg/derived_init_6.f90	(working copy)
***************
*** 0 ****
--- 1,60 ----
+ ! { dg-do compile }
+ !
+ ! Test the fix for PR69654 in which the derived type 'ty_foo2' was
+ ! not completely built in time for initialization thereby causing an ICE.
+ !
+ ! Contributed by Hossein Talebi  <talebi.hossein@gmail.com>
+ !
+  Module foo_pointers_class
+    implicit none
+     type :: ty_foo_pointers
+       integer :: scale=0
+       integer,pointer :: universe_ulogfile => NULL()
+       class(*),pointer :: foo => NULL()
+     end type ty_foo_pointers
+
+    type :: ty_part_ptrs
+       character(len=80),pointer :: part_name => NULL()
+       class(*),pointer     :: part_fem => NULL()
+    end type
+
+    type :: ty_class_basis
+       integer :: id=0
+     end type ty_class_basis
+
+    type :: ty_store_sclass
+       class(ty_class_basis),allocatable :: OBJ
+    end type ty_store_sclass
+ End Module foo_pointers_class
+
+ Module foo_class
+    use foo_pointers_class
+    implicit none
+    type,extends(ty_class_basis) :: ty_foo2
+       character(200)                     :: title
+       logical                            :: isInit=.false.
+       type(ty_foo_pointers)              :: foo
+    end type ty_foo2
+ ENd Module foo_class
+
+
+ Module foo_scripts_mod
+   implicit none
+ contains
+
+ subroutine  foo_script1
+    use foo_class, only: ty_foo2
+    implicit none
+    type(ty_foo2) :: foo2
+    integer i
+
+    Call foo_init2(foo2)
+ end subroutine  foo_script1
+
+ subroutine foo_init2(self)
+    use foo_class, only: ty_foo2
+    type(ty_foo2),target :: self
+    self%isInit=.true.
+ end subroutine foo_init2
+
+ End Module foo_scripts_mod