|
| 1 | +! |
| 2 | +! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +! See https://llvm.org/LICENSE.txt for license information. |
| 4 | +! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | +! |
| 6 | +! Test for LBOUND and UBOUND of assumed-shape formal when the corresponding |
| 7 | +! acutal is a struct component. |
| 8 | + |
| 9 | +program test |
| 10 | + implicit none |
| 11 | + type my_type |
| 12 | + integer :: x(2,3,4) |
| 13 | + integer, allocatable :: x_alloc(:, :, :) |
| 14 | + integer, pointer :: x_ptr(:, :, :) |
| 15 | + end type |
| 16 | + type(my_type) :: obj |
| 17 | + integer, allocatable :: arr_res(:) |
| 18 | + character(len=:), allocatable :: char_res |
| 19 | + integer :: i |
| 20 | + |
| 21 | + allocate(obj%x_alloc(2:3, 3:5, 4:7)) |
| 22 | + allocate(obj%x_ptr(2:3, 3:5, 4:7)) |
| 23 | + |
| 24 | + arr_res = array_test_specified_lb(1, 0, -1, obj%x) |
| 25 | + if (size(arr_res) /= 8 .or. any(arr_res /= 1)) STOP 1 |
| 26 | + arr_res = array_test_specified_lb(2, 1, 0, obj%x(2:, 3:, 2:)) |
| 27 | + if (size(arr_res) /= 4 .or. any(arr_res /= 1)) STOP 2 |
| 28 | + arr_res = array_test_missing_lb(obj%x_alloc) |
| 29 | + if (size(arr_res) /= 3 .or. any(arr_res /= 2)) STOP 3 |
| 30 | + arr_res = array_test_specified_lb(1, 0, -1, obj%x_alloc) |
| 31 | + if (size(arr_res) /= 8 .or. any(arr_res /= 1)) STOP 4 |
| 32 | + arr_res = array_test_missing_lb(obj%x_ptr) |
| 33 | + if (size(arr_res) /= 3 .or. any(arr_res /= 2)) STOP 5 |
| 34 | + |
| 35 | + char_res = char_test_specified_lb(1, 0, -1, obj%x) |
| 36 | + if (len(char_res) /= 8 .or. char_res /= 'aaaaaaaa') STOP 6 |
| 37 | + char_res = char_test_specified_lb(2, 1, 0, obj%x(2:, 3:, 2:)) |
| 38 | + if (len(char_res) /= 4 .or. char_res /= 'aaaa') STOP 7 |
| 39 | + char_res = char_test_missing_lb(obj%x_alloc) |
| 40 | + if (len(char_res) /= 3 .or. char_res /= 'bbb') STOP 8 |
| 41 | + char_res = char_test_specified_lb(1, 0, -1, obj%x_alloc) |
| 42 | + if (len(char_res) /= 8 .or. char_res /= 'aaaaaaaa') STOP 9 |
| 43 | + char_res = char_test_missing_lb(obj%x_ptr) |
| 44 | + if (len(char_res) /= 3 .or. char_res /= 'bbb') STOP 10 |
| 45 | + |
| 46 | + arr_res = test_noncnst_dim(1, 0, -1, obj%x, 1, 2, 3) |
| 47 | + if (size(arr_res) /= 8 .or. any(arr_res /= 1)) STOP 11 |
| 48 | + |
| 49 | + print *, "PASS" |
| 50 | +contains |
| 51 | + function array_test_specified_lb(l1, l2, l3, a) result(res) |
| 52 | + integer :: l1, l2, l3 |
| 53 | + integer :: a(l1:, l2:, l3:) |
| 54 | + integer :: res(1:ubound(a, 1) * ubound(a, 2) * ubound(a, 3)) |
| 55 | + res = 1 |
| 56 | + end function |
| 57 | + |
| 58 | + function array_test_missing_lb(a) result(res) |
| 59 | + integer :: a(:, :, :) |
| 60 | + integer :: res(1:lbound(a, 1) + lbound(a, 2) + lbound(a, 3)) |
| 61 | + res = 2 |
| 62 | + end function |
| 63 | + |
| 64 | + function char_test_specified_lb(l1, l2, l3, a) result(res) |
| 65 | + integer :: l1, l2, l3 |
| 66 | + integer :: a(l1:, l2:, l3:) |
| 67 | + character(len=ubound(a, 1) * ubound(a, 2) * ubound(a, 3)) :: res |
| 68 | + res = repeat('a', ubound(a, 1) * ubound(a, 2) * ubound(a, 3)) |
| 69 | + end function |
| 70 | + |
| 71 | + function char_test_missing_lb(a) result(res) |
| 72 | + integer :: a(:, :, :) |
| 73 | + character(len=lbound(a, 1) + lbound(a, 2) + lbound(a, 3)) :: res |
| 74 | + res = repeat('b', lbound(a, 1) + lbound(a, 2) + lbound(a, 3)) |
| 75 | + end function |
| 76 | + |
| 77 | + function test_noncnst_dim(l1, l2, l3, a, d1, d2, d3) result(res) |
| 78 | + integer :: l1, l2, l3 |
| 79 | + integer :: a(l1:, l2:, l3:) |
| 80 | + integer :: d1, d2, d3 |
| 81 | + integer :: res(1:ubound(a, d1) * ubound(a, d2) * ubound(a, d3)) |
| 82 | + res = 1 |
| 83 | + end function |
| 84 | +end program |
0 commit comments