$ /irun/bin/gfortran bug_matlib_1.f90
bug_matlib_1.f90: In function 'MAIN__':
bug_matlib_1.f90:20: internal compiler error: in gfc_conv_component_ref, at fort
ran/trans-expr.c:268

This programme compiles and runs correctly, as it stands, with other brands of 
compiler.

By raising the comment on either of the two lines in the main programme, the 
problem goes away and it compiles and runs correctly.  It seems that the module 
variable is not being instantiated without being explicitly referenced 
somewhere in the main programme.  I cannot find any requirement on this in the 
ISO standard but its seems reasonable to me that a direct reference be 
unnecessary. 

(Yes, I know that this will cause memory leaks, as it stands!  The example is a 
distillate from a much larger programme, which has implicit reference counting 
and garbage cleaning.  BTW gfortran performs much better than any compiler that 
I have access to because it treats temporaries very hygenically.)

module matrix
  type                            :: datatype
    real, pointer                 :: rep(:)     !the data
  end type datatype
  type                            :: mattype
    type(datatype), pointer       :: datarep    !points to representation
  end type mattype
  type(datatype), pointer         :: repbase => null() !origin of linked list
contains
  function mat_make( n ) result (temp_mat)
    type(mattype), POINTER        :: temp_mat
    ALLOCATE(temp_mat)
    allocate(temp_mat%datarep) 
    allocate(temp_mat%datarep%rep(n))
  end function mat_make
end module matrix  
program test_matrix
  use matrix
  type(mattype), POINTER           :: mymat1 
  mymat1 => mat_make( 2 )
  do i = 1,2
    mymat1%datarep%rep(i) = float(i)
  end do
  print * , "rep=", mymat1%datarep%rep
!  print * , "repbase? ", associated(repbase)
!  repbase => null()
end program test_matrix

-- 
           Summary: Non explicit instantiation of module variable in MAIN
                    causes ICE
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: paul dot richard dot thomas at cea dot fr
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to