| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test fix of PR109066, which caused segfaults as below |
| 4 |
! |
| 5 |
! Contributed by Andrew Benson <[email protected]> |
| 6 |
! |
| 7 |
module bugMod |
| 8 |
|
| 9 |
type :: rm |
| 10 |
integer :: c=0 |
| 11 |
contains |
| 12 |
procedure :: rma |
| 13 |
generic :: assignment(=) => rma |
| 14 |
end type rm |
| 15 |
|
| 16 |
type :: lc |
| 17 |
type(rm) :: lm |
| 18 |
end type lc |
| 19 |
|
| 20 |
contains |
| 21 |
|
| 22 |
impure elemental subroutine rma(to,from) |
| 23 |
implicit none |
| 24 |
class(rm), intent(out) :: to |
| 25 |
class(rm), intent(in) :: from |
| 26 |
to%c = -from%c |
| 27 |
return |
| 28 |
end subroutine rma |
| 29 |
|
| 30 |
end module bugMod |
| 31 |
|
| 32 |
program bug |
| 33 |
use bugMod |
| 34 |
implicit none |
| 35 |
type(lc), pointer :: i, j(:) |
| 36 |
|
| 37 |
allocate (i) |
| 38 |
i = lc (rm (1)) ! Segmentation fault |
| 39 |
if (i%lm%c .ne. -1) stop 1 |
| 40 |
i = i_ptr () ! Segmentation fault |
| 41 |
if (i%lm%c .ne. 1) stop 2 |
| 42 |
|
| 43 |
allocate (j(2)) |
| 44 |
j = [lc (rm (2)), lc (rm (3))] ! Segmentation fault |
| 45 |
if (any (j%lm%c .ne. [-2,-3])) stop 3 |
| 46 |
j = j_ptr () ! Worked! |
| 47 |
if (any (j%lm%c .ne. [2,3])) stop 4 |
| 48 |
|
| 49 |
contains |
| 50 |
|
| 51 |
function i_ptr () result(res) |
| 52 |
type(lc), pointer :: res |
| 53 |
res => i |
| 54 |
end function |
| 55 |
|
| 56 |
function j_ptr () result(res) |
| 57 |
type(lc), pointer :: res (:) |
| 58 |
res => j |
| 59 |
end function |
| 60 |
|
| 61 |
end program bug |