------- Comment #12 from pault at gcc dot gnu dot org 2010-06-05 10:40 ------- (In reply to comment #11) OK, all this has a simple explanation. A revamped version of the original testcase segfaults in runtime, at -O0.
! { dg-do compile } ! Test the fix for PR43895, in which the dummy 'a' was not ! dereferenced for the deallocation of component 'a', as required ! for INTENT(OUT). ! ! Contributed by Salvatore Filippone <sfilipp...@uniroma2.it> ! module d_mat_mod type :: base_sparse_mat end type base_sparse_mat type, extends(base_sparse_mat) :: d_base_sparse_mat integer :: i end type d_base_sparse_mat type :: d_sparse_mat class(d_base_sparse_mat), allocatable :: a end type d_sparse_mat end module d_mat_mod use d_mat_mod type(d_sparse_mat) :: b allocate (b%a) b%a%i = 42 call bug14 (b) if (allocated (b%a)) call abort contains subroutine bug14(a) implicit none type(d_sparse_mat), intent(out) :: a end subroutine bug14 end ! { dg-final { cleanup-modules "d_mat_mod " } } The reason is quite clear from the code below: bug14 (struct d_sparse_mat & restrict a) { if (a.a.$data != 0B) { __builtin_free ((void *) a.a.$data); } a.a.$data = 0B; } The dummy 'a' needs dereferencing, thus... bug14 (struct d_sparse_mat & restrict a) { if (a->a.$data != 0B) { __builtin_free ((void *) a->a.$data); } a->a.$data = 0B; } This patch is regtesting right now: Index: /svn/trunk/gcc/fortran/trans-array.c =================================================================== *** /svn/trunk/gcc/fortran/trans-array.c (revision 159851) --- /svn/trunk/gcc/fortran/trans-array.c (working copy) *************** structure_alloc_comps (gfc_symbol * der_ *** 5951,5957 **** gfc_init_block (&fnblock); ! if (POINTER_TYPE_P (TREE_TYPE (decl)) && rank != 0) decl = build_fold_indirect_ref_loc (input_location, decl); --- 5951,5958 ---- gfc_init_block (&fnblock); ! if ((POINTER_TYPE_P (TREE_TYPE (decl)) && rank != 0) ! || (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE && rank == 0)) decl = build_fold_indirect_ref_loc (input_location, decl); Cheers Paul -- pault at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot gnu |pault at gcc dot gnu dot org |dot org | Status|NEW |ASSIGNED Last reconfirmed|2010-04-26 15:04:01 |2010-06-05 10:40:32 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43895