[clang][Driver] Support simplified triple versions for config files (#111387)
[llvm-project.git] / flang / test / Lower / Intrinsics / len.f90
blob16b865cc89aad40e9f399abae4d4a694d553ce96
1 ! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false %s -o - | FileCheck %s
3 ! CHECK-LABEL: len_test
4 subroutine len_test(i, c)
5 integer :: i
6 character(*) :: c
7 ! CHECK: %[[c:.*]]:2 = fir.unboxchar %arg1
8 ! CHECK: %[[xx:.*]] = fir.convert %[[c]]#1 : (index) -> i32
9 ! CHECK: fir.store %[[xx]] to %arg0
10 i = len(c)
11 end subroutine
13 ! CHECK-LABEL: len_test_array
14 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"}, %[[arg1:.*]]: !fir.boxchar<1> {fir.bindc_name = "c"}
15 subroutine len_test_array(i, c)
16 integer :: i
17 character(*) :: c(100)
18 ! CHECK: %[[c:.*]]:2 = fir.unboxchar %[[arg1]]
19 ! CHECK: %[[xx:.*]] = fir.convert %[[c]]#1 : (index) -> i32
20 ! CHECK: fir.store %[[xx]] to %[[arg0]]
21 i = len(c)
22 end subroutine
24 ! CHECK-LABEL: func @_QPlen_test_assumed_shape_array(
25 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"},
26 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?x!fir.char<1,?>>> {fir.bindc_name = "c"}) {
27 subroutine len_test_assumed_shape_array(i, c)
28 integer :: i
29 character(*) :: c(:)
30 ! CHECK: %[[VAL_2:.*]] = fir.box_elesize %[[VAL_1]] : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> index
31 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (index) -> i32
32 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_0]] : !fir.ref<i32>
33 i = len(c)
34 end subroutine
36 ! CHECK-LABEL: func @_QPlen_test_array_alloc(
37 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"},
38 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>> {fir.bindc_name = "c"}) {
39 subroutine len_test_array_alloc(i, c)
40 integer :: i
41 character(:), allocatable :: c(:)
42 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
43 ! CHECK: %[[VAL_3:.*]] = fir.box_elesize %[[VAL_2]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> index
44 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (index) -> i32
45 ! CHECK: fir.store %[[VAL_4]] to %[[VAL_0]] : !fir.ref<i32>
46 i = len(c)
47 end subroutine
49 ! CHECK-LABEL: func @_QPlen_test_array_local_alloc(
50 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"})
51 subroutine len_test_array_local_alloc(i)
52 integer :: i
53 character(:), allocatable :: c(:)
54 ! CHECK: %[[VAL_5:.*]] = fir.alloca index {uniq_name = "_QFlen_test_array_local_allocEc.len"}
55 ! CHECK: %[[VAL_7:.*]] = arith.constant 10 : i32
56 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_7]] : (i32) -> index
57 ! CHECK: fir.store %[[VAL_10]] to %[[VAL_5]] : !fir.ref<index>
58 allocate(character(10):: c(100))
59 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_5]] : !fir.ref<index>
60 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (index) -> i32
61 ! CHECK: fir.store %[[VAL_14]] to %[[VAL_0]] : !fir.ref<i32>
62 i = len(c)
63 end subroutine
65 ! CHECK-LABEL: func @_QPlen_test_alloc_explicit_len(
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"},
67 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"},
68 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>> {fir.bindc_name = "c"}) {
69 subroutine len_test_alloc_explicit_len(i, n, c)
70 integer :: i
71 integer :: n
72 character(n), allocatable :: c(:)
73 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
74 ! CHECK: %[[c0_i32:.*]] = arith.constant 0 : i32
75 ! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[VAL_3]], %[[c0_i32]] : i32
76 ! CHECK: %[[len:.*]] = arith.select %[[cmp]], %[[VAL_3]], %[[c0_i32]] : i32
77 ! CHECK: fir.store %[[len]] to %[[VAL_0]] : !fir.ref<i32>
78 i = len(c)
79 end subroutine
81 ! CHECK-LABEL: func @_QPlen_test_pointer_explicit_len(
82 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"},
83 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"},
84 subroutine len_test_pointer_explicit_len(i, n, c)
85 integer :: i
86 integer :: n
87 character(n), pointer :: c(:)
88 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
89 ! CHECK: %[[c0_i32:.*]] = arith.constant 0 : i32
90 ! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[VAL_3]], %[[c0_i32]] : i32
91 ! CHECK: %[[len:.*]] = arith.select %[[cmp]], %[[VAL_3]], %[[c0_i32]] : i32
92 ! CHECK: fir.store %[[len]] to %[[VAL_0]] : !fir.ref<i32>
93 i = len(c)
94 end subroutine
96 ! CHECK-LABEL: func @_QPlen_test_assumed_shape_explicit_len(
97 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"},
98 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"},
99 subroutine len_test_assumed_shape_explicit_len(i, n, c)
100 integer :: i
101 integer :: n
102 character(n) :: c(:)
103 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
104 ! CHECK: %[[c0_i32:.*]] = arith.constant 0 : i32
105 ! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[VAL_3]], %[[c0_i32]] : i32
106 ! CHECK: %[[len:.*]] = arith.select %[[cmp]], %[[VAL_3]], %[[c0_i32]] : i32
107 ! CHECK: fir.store %[[len]] to %[[VAL_0]] : !fir.ref<i32>
108 i = len(c)
109 end subroutine