2 ! { dg-options "-fdump-tree-original" }
5 ! Contributed by Rich Townsend
7 ! The problem was an ICE when trying to deallocate the
8 ! result variable "x_unique".
10 function unique_A (x
, sorted
) result (x_unique
)
12 character(*), dimension(:), intent(in
) :: x
13 logical, intent(in
), optional
:: sorted
14 character(LEN(x
)), dimension(:), allocatable
:: x_unique
17 character(LEN(x
)), dimension(SIZE(x
)) :: x_sorted
19 logical, dimension(SIZE(x
)) :: mask
21 integer, external :: b3ss_index
25 if(PRESENT(sorted
)) then
31 ! If necessary, sort x
36 x_sorted
= x(b3ss_index(x
))
39 ! Set up the unique array
43 mask
= (/.TRUE
.,x_sorted(2:n_x
) /= x_sorted(1:n_x
-1)/)
45 allocate(x_unique(COUNT(mask
)))
47 x_unique
= PACK(x_sorted
, MASK
=mask
)
54 ! { dg-final { scan-tree-dump-times "__builtin_free" 5 "original" } }
55 ! { dg-final { cleanup-tree-dump "original" } }