| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test the fix for PR84868. Module 'orig' and the call to 'f_orig' is the |
| 4 |
! original bug. The rest tests variants and the fix for a gimplifier ICE. |
| 5 |
! |
| 6 |
! Subroutine 'h' and calls to it were introduced to check the corrections |
| 7 |
! needed to fix additional problems, noted in the review of the patch by |
| 8 |
! Harald Anlauf |
| 9 |
! |
| 10 |
! Contributed by Gerhard Steinmetz <[email protected]> |
| 11 |
! |
| 12 |
module orig |
| 13 |
character(:), allocatable :: c |
| 14 |
integer :: ans1(3,3), ans2(3), ans3(2) |
| 15 |
contains |
| 16 |
function f_orig(n) result(z) |
| 17 |
character(2), parameter :: c(3) = ['x1', 'y ', 'z2'] |
| 18 |
integer, intent(in) :: n |
| 19 |
character(len_trim(c(n))) :: z |
| 20 |
z = c(n) |
| 21 |
end |
| 22 |
function h(n) result(z) |
| 23 |
integer, intent(in) :: n |
| 24 |
character(2), parameter :: c(3,3) = & |
| 25 |
reshape (['ab','c ','de','f ','gh','i ','jk','l ','mn'],[3,3]) |
| 26 |
character(4), parameter :: chr(3) = ['ab ',' cd','e f '] |
| 27 |
character(len_trim(c(n,n))) :: z |
| 28 |
z = c(n,n) |
| 29 |
! Make sure that full arrays are correctly scalarized both having been previously |
| 30 |
! used with an array reference and not previously referenced. |
| 31 |
ans1 = len_trim (c) |
| 32 |
ans2 = len_trim (chr) |
| 33 |
! Finally check a slightly more complicated array reference |
| 34 |
ans3 = len_trim (c(1:n+1:2,n-1)) |
| 35 |
end |
| 36 |
end module orig |
| 37 |
|
| 38 |
module m |
| 39 |
character(:), allocatable :: c |
| 40 |
contains |
| 41 |
function f(n, c) result(z) |
| 42 |
character (2) :: c(:) |
| 43 |
integer, intent(in) :: n |
| 44 |
character(len_trim(c(n))) :: z |
| 45 |
z = c(n) |
| 46 |
end |
| 47 |
subroutine foo (pc) |
| 48 |
character(2) :: pc(:) |
| 49 |
if (any ([(len (f(i, pc)), i = 1,3)] .ne. [2,1,2])) stop 1 |
| 50 |
end |
| 51 |
end |
| 52 |
program p |
| 53 |
use m |
| 54 |
use orig |
| 55 |
character (2) :: pc(3) = ['x1', 'y ', 'z2'] |
| 56 |
integer :: i |
| 57 |
|
| 58 |
if (any ([(len (f_orig(i)), i = 1,3)] .ne. [2,1,2])) stop 2 ! ICE |
| 59 |
|
| 60 |
call foo (pc) |
| 61 |
if (any ([(len (g(i, pc)), i = 1,3)] .ne. [2,1,2])) stop 3 |
| 62 |
if (any ([(bar1(i), i = 1,3)] .ne. [2,1,2])) stop 4 |
| 63 |
if (any ([(bar2(i), i = 1,3)] .ne. [2,1,2])) stop 5 |
| 64 |
|
| 65 |
if (h(2) .ne. 'gh') stop 6 |
| 66 |
if (any (ans1 .ne. reshape ([2,1,2,1,2,1,2,1,2],[3,3]))) stop 7 |
| 67 |
if (any (ans2 .ne. [2,4,3])) stop 8 |
| 68 |
if (any (ans3 .ne. [2,2])) stop 9 |
| 69 |
contains |
| 70 |
function g(n, c) result(z) |
| 71 |
character (2) :: c(:) |
| 72 |
integer, intent(in) :: n |
| 73 |
character(len_trim(c(n))) :: z |
| 74 |
z = c(n) |
| 75 |
end |
| 76 |
integer function bar1 (i) |
| 77 |
integer :: i |
| 78 |
bar1 = len (f(i, pc)) ! ICE in is_gimple_min_invariant |
| 79 |
end |
| 80 |
integer function bar2 (i) |
| 81 |
integer :: i |
| 82 |
bar2 = len (g(i, pc)) |
| 83 |
end |
| 84 |
end |