3 ! Test the fix for PR84109 in which the call to the elemental function
4 ! 'adjustl' was being added before the scalarization loop in the assignment.
5 ! Since the result temporary was being declared in the loop body, this
6 ! drove the gimplifier crazy. It is sufficient to compile this testcase
7 ! since it used to ICE. This is the intrinsic counterpart to PR87239,
8 ! which is tested for the absence of an ICE in elemental_function_2.f90.
9 ! In this fix, a further improvement was to keep scalar calls outside the
10 ! scalarization loop and this is tested with 'my_adjustl'.
12 ! Contributed by Willem Vermin <wvermin@gmail.com>
16 character(len
=:), allocatable
:: c(:)
19 allocate(character(len
=20) :: c(10))
21 c
= adjustl(c
) ! Used to ICE
22 if (trim (c(1)) .ne
. "ab") stop 1
24 c
= my_adjustl (" abcdefg ")
25 if (trim (c(1)) .ne
. "abcdefg") stop 2
26 if (cnt
.ne
. 1) stop 3 ! Outside the scalarization loop
27 if (size (c
, 1) .ne
. 10) stop 4
28 if (len (c
) .ne
. 20) stop 5
31 c
= my_adjustl ([" uv ", " xy "])
32 if (trim (c(2)) .ne
. "xy") stop 6
33 if (cnt
.ne
. size (c
, 1)) stop 7 ! Inside the scalarization loop
34 if (size (c
, 1) .ne
. 2) stop 8
38 impure elemental
function my_adjustl(arg
) result (res
)
39 character(*), intent(in
) :: arg
40 character(len
= len (arg
)) :: res
42 cnt
= cnt
+ 1 ! Test how many calls are made