This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pr22146 - elemental subroutines


Richard,

I have to thank you for triggering a useful line of investigation, following your pedagogic message. The following program is broken in the second forall block because gfortran turns the interface assignment into a subroutine call, which gfc_trans_forall_1 has no means to deal with.  The frontend catches an explicit subroutine call, so I propose to add code to the middle-end to translate a subroutine call.  Lahey thinks the code is good.

Cheers

Paul

module type
  type itype
    integer :: i
  end type itype
end module type

module assign
  interface assignment (=)
    module procedure itype_to_int
  end interface
contains
  elemental subroutine itype_to_int (i, it)
    use type
    type(itype), intent(in) :: it
    integer, intent(out) :: i
    i = it%i
  end subroutine itype_to_int

  elemental function i_from_itype (it) result (i)
    use type
    type(itype), intent(in) :: it
    integer :: i
    i = it
  end function i_from_itype

end module assign

program test_assign
  use type
  use assign
  type(itype) :: x(2, 2)
  integer :: i(2, 2)

  x = reshape ((/(itype (2*j), j = 1,4)/), (/2,2/))

  forall (j = 1:2, k = 1:2)
    i(j, k) = i_from_itype (x (j, k))
  end forall

  forall (j = 1:2, k = 1:2)
    i(j, k) = x (j, k)         ! ICE at trans-stmt.c:2562
  end forall

  print *, i
end program test_assign


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]