[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / Intrinsics / maxval.f90
bloba442926ff1b0bb0d7166814fc1439443573fe02f
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! CHECK-LABEL: func @_QPmaxval_test(
4 ! CHECK-SAME: %[[arg0:.*]]: !fir.box<!fir.array<?xi32>>{{.*}}) -> i32
5 integer function maxval_test(a)
6 integer :: a(:)
7 ! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
8 ! CHECK-DAG: %[[a2:.*]] = fir.absent !fir.box<i1>
9 ! CHECK-DAG: %[[a4:.*]] = fir.convert %[[arg0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none>
10 ! CHECK: %[[a6:.*]] = fir.convert %[[c0]] : (index) -> i32
11 ! CHECK: %[[a7:.*]] = fir.convert %[[a2]] : (!fir.box<i1>) -> !fir.box<none>
12 maxval_test = maxval(a)
13 ! CHECK: %{{.*}} = fir.call @_FortranAMaxvalInteger4(%[[a4]], %{{.*}}, %{{.*}}, %[[a6]], %[[a7]]) {{.*}}: (!fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> i32
14 end function
16 ! CHECK-LABEL: func @_QPmaxval_test2(
17 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.char<1>>, %[[arg1:.*]]: index, %[[arg2:.*]]: !fir.box<!fir.array<?x!fir.char<1>>> {fir.bindc_name = "a"}) -> !fir.boxchar<1> {
18 character function maxval_test2(a)
19 character :: a(:)
20 ! CHECK-DAG: %[[a0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.char<1,?>>>
21 ! CHECK: %[[a1:.*]] = fir.absent !fir.box<i1>
22 ! CHECK-DAG: %[[a5:.*]] = fir.convert %[[a0]] : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) -> !fir.ref<!fir.box<none>>
23 ! CHECK: %[[a6:.*]] = fir.convert %[[arg2]] : (!fir.box<!fir.array<?x!fir.char<1>>>) -> !fir.box<none>
24 ! CHECK-DAG: %[[a8:.*]] = fir.convert %[[a1]] : (!fir.box<i1>) -> !fir.box<none>
25 maxval_test2 = maxval(a)
26 ! CHECK: %{{.*}} = fir.call @_FortranAMaxvalCharacter(%[[a5]], %[[a6]], %{{.*}}, %{{.*}}, %[[a8]]) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32, !fir.box<none>) -> none
27 end function
29 ! CHECK-LABEL: func @_QPmaxval_test3(
30 ! CHECK-SAME: %[[arg0:.*]]: !fir.box<!fir.array<?x?xi32>>{{.*}}, %[[arg1:.*]]: !fir.box<!fir.array<?xi32>>
31 subroutine maxval_test3(a,r)
32 integer :: a(:,:)
33 integer :: r(:)
34 ! CHECK-DAG: %[[c2_i32:.*]] = arith.constant 2 : i32
35 ! CHECK-DAG: %[[a0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>>
36 ! CHECK: %[[a1:.*]] = fir.absent !fir.box<i1>
37 ! CHECK-DAG: %[[a6:.*]] = fir.convert %[[a0]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<none>>
38 ! CHECK: %[[a7:.*]] = fir.convert %[[arg0]] : (!fir.box<!fir.array<?x?xi32>>) -> !fir.box<none>
39 ! CHECK-DAG: %[[a9:.*]] = fir.convert %[[a1]] : (!fir.box<i1>) -> !fir.box<none>
40 r = maxval(a,dim=2)
41 ! CHECK: %{{.*}} = fir.call @_FortranAMaxvalDim(%[[a6]], %[[a7]], %[[c2_i32]], %{{.*}}, %{{.*}}, %[[a9]]) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, !fir.ref<i8>, i32, !fir.box<none>) -> none
42 ! CHECK: %[[a11:.*]] = fir.load %[[a0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
43 ! CHECK-DAG: %[[a13:.*]] = fir.box_addr %[[a11]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
44 ! CHECK-DAG: fir.freemem %[[a13]]
45 end subroutine
47 ! CHECK-LABEL: func @_QPtest_maxval_optional_scalar_mask(
48 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.logical<4>>
49 subroutine test_maxval_optional_scalar_mask(mask, array)
50 integer :: array(:)
51 logical, optional :: mask
52 print *, maxval(array, mask)
53 ! CHECK: %[[VAL_7:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<!fir.logical<4>>) -> i1
54 ! CHECK: %[[VAL_8:.*]] = fir.embox %[[VAL_1]] : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
55 ! CHECK: %[[VAL_9:.*]] = fir.absent !fir.box<!fir.logical<4>>
56 ! CHECK: %[[VAL_10:.*]] = arith.select %[[VAL_7]], %[[VAL_8]], %[[VAL_9]] : !fir.box<!fir.logical<4>>
57 ! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_10]] : (!fir.box<!fir.logical<4>>) -> !fir.box<none>
58 ! CHECK: fir.call @_FortranAMaxvalInteger4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_17]]) {{.*}}: (!fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> i32
59 end subroutine
61 ! CHECK-LABEL: func @_QPtest_maxval_optional_array_mask(
62 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>>
63 subroutine test_maxval_optional_array_mask(mask, array)
64 integer :: array(:)
65 logical, optional :: mask(:)
66 print *, maxval(array, mask)
67 ! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> !fir.box<none>
68 ! CHECK: fir.call @_FortranAMaxvalInteger4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_13]]) {{.*}}: (!fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> i32
69 end subroutine