| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-O2 -fcheck=bounds -fno-automatic" } |
| 3 |
! PR fortran/106546 - FE temporaries have to be automatic |
| 4 |
! Original test case by Solomon Gibbs |
| 5 |
|
| 6 |
subroutine do_multiply() |
| 7 |
implicit none |
| 8 |
|
| 9 |
integer :: rank |
| 10 |
real(8) :: draw |
| 11 |
|
| 12 |
real(8) :: x1(6), x2(6) |
| 13 |
real(8), allocatable :: K(:,:), J(:,:), z(:) |
| 14 |
|
| 15 |
character(len=300) :: out |
| 16 |
! Randomly select rank of operation 0 ... 6 |
| 17 |
call random_number(draw) |
| 18 |
if (draw .lt. 1/7.0d0) then |
| 19 |
rank = 0 |
| 20 |
elseif (draw .lt. 2/7.0d0) then |
| 21 |
rank = 1 |
| 22 |
elseif (draw .lt. 3/7.0d0) then |
| 23 |
rank = 2 |
| 24 |
elseif (draw .lt. 4/7.0d0) then |
| 25 |
rank = 3 |
| 26 |
elseif (draw .lt. 5/7.0d0) then |
| 27 |
rank = 4 |
| 28 |
elseif (draw .lt. 6/7.0d0) then |
| 29 |
rank = 5 |
| 30 |
else |
| 31 |
rank = 6 |
| 32 |
endif |
| 33 |
|
| 34 |
allocate(K(rank, 6)) |
| 35 |
allocate(J(rank, rank)) |
| 36 |
allocate(z(rank)) |
| 37 |
|
| 38 |
call random_number(x1) |
| 39 |
call random_number(x2) |
| 40 |
call random_number(K) |
| 41 |
call random_number(J) |
| 42 |
call random_number(z) |
| 43 |
|
| 44 |
! multiply allocatables using array temporaries |
| 45 |
! Problem occurs here |
| 46 |
z = matmul(J, matmul(K, x2 - x1)) |
| 47 |
|
| 48 |
! Output z to prevent optimizer elimination |
| 49 |
write (out,*) rank," ",z |
| 50 |
|
| 51 |
deallocate(z, J, K) |
| 52 |
|
| 53 |
end subroutine do_multiply |
| 54 |
|
| 55 |
program bogus |
| 56 |
implicit none |
| 57 |
|
| 58 |
integer :: i |
| 59 |
do i=1,100 |
| 60 |
call do_multiply() |
| 61 |
end do |
| 62 |
|
| 63 |
end program bogus |