This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/67539] New: Segmentation fault with elemental defined assignment and scalar function at the RHS
- From: "mrestelli at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 10 Sep 2015 13:04:32 +0000
- Subject: [Bug fortran/67539] New: Segmentation fault with elemental defined assignment and scalar function at the RHS
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67539
Bug ID: 67539
Summary: Segmentation fault with elemental defined assignment
and scalar function at the RHS
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: mrestelli at gmail dot com
Target Milestone: ---
The attached code produces a segmentation fault:
$ gfortran --version
GNU Fortran (GCC) 6.0.0 20150910 (experimental)
$ ./test
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x7FD288EF6757
#1 0x7FD288EF6D5E
#2 0x7FD28842EE8F
#3 0x400B69 in __m_MOD_copy_t_a at test.f90:17 (discriminator 3)
#4 0x400D15 in p at test.f90:40 (discriminator 2)
Notice that both workarounds a) using a scalar temporary tmp and b)
assigning to each element separately work.
module m
implicit none
type :: t_a
real, allocatable :: x
end type t_a
interface assignment(=)
module procedure copy_t_a
end interface
contains
elemental subroutine copy_t_a(y,x)
type(t_a), intent(in) :: x
type(t_a), intent(out) :: y
allocate( y%x , source=x%x )
end subroutine copy_t_a
elemental function new_t_a(x) result(res)
real, intent(in) :: x
type(t_a) :: res
allocate( res%x )
res%x = x
end function new_t_a
end module m
program p
use m
implicit none
integer :: i
type(t_a) :: tmp
type(t_a), allocatable :: v(:)
allocate( v(2) )
v = new_t_a(1.5) ! -> segmentation fault
!tmp = new_t_a(1.5) ! -> OK
!v = tmp
!do i=1,size(v) ! -> also OK
! v(i) = new_t_a(1.5)
!enddo
do i=1,size(v)
write(*,*) " i = ",i
write(*,*) allocated(v(i)%x)
write(*,*) v(i)%x
enddo
end program p