1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
5 ! CHECK-LABEL: func @_QPlbound_test(
6 ! CHECK: %[[VAL_0:.*]] = fir.load %arg1 : !fir.ref<i64>
7 ! CHECK: %[[VAL_1:.*]] = fir.rebox %arg0 : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.array<?x?xf32>>
8 subroutine lbound_test(a
, dim
, res
)
9 real, dimension(:, :) :: a
11 ! CHECK: %[[VAL_2:.*]] = fir.address_of(
12 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_1]] : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
13 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32
14 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_2]]
15 ! CHECK: %[[VAL_6:.*]] = fir.call @_FortranALboundDim(%[[VAL_3]], %[[VAL_4]], %[[VAL_5]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
16 ! CHECK: fir.store %[[VAL_6]] to %arg2 : !fir.ref<i64>
17 res
= lbound(a
, dim
, 8)
20 ! CHECK-LABEL: func @_QPlbound_test_2(
21 ! CHECK: %[[VAL_c1_i64:.*]] = arith.constant 1 : i64
22 ! CHECK: %[[VAL_0:.*]] = fir.convert %[[VAL_c1_i64]] : (i64) -> index
23 ! CHECK: %[[VAL_c2_i64:.*]] = arith.constant 2 : i64
24 ! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_c2_i64]] : (i64) -> index
25 ! CHECK: %[[VAL_2:.*]] = fir.load %arg1 : !fir.ref<i64>
26 subroutine lbound_test_2(a
, dim
, res
)
27 real, dimension(:, 2:) :: a
29 ! CHECK: %[[VAL_3:.*]] = fir.shift %[[VAL_0]], %[[VAL_1]] : (index, index) -> !fir.shift<2>
30 ! CHECK: %[[VAL_4:.*]] = fir.rebox %arg0(%[[VAL_3]]) : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
31 ! CHECK: %[[VAL_5:.*]] = fir.address_of(
32 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_4]] : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
33 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (i64) -> i32
34 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_5]]
35 ! CHECK: %[[VAL_9:.*]] = fir.call @_FortranALboundDim(%[[VAL_6]], %[[VAL_7]], %[[VAL_8]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
36 ! CHECK: fir.store %[[VAL_9]] to %arg2 : !fir.ref<i64>
37 res
= lbound(a
, dim
, 8)
40 subroutine lbound_test_3(a
, dim
, res
)
41 real, dimension(2:10, 3:*) :: a
43 ! CHECK: %[[VAL_1:.*]] = fir.load %arg1 : !fir.ref<i64>
44 ! CHECK: %[[VAL_0:.*]] = arith.constant 1 : index
45 ! CHECK: %[[VAL_2:.*]] = fir.shape_shift %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_0]] : (index, index, index, index) -> !fir.shapeshift<2>
46 ! CHECK: %[[VAL_3:.*]] = fir.embox %arg0(%[[VAL_2]]) : (!fir.ref<!fir.array<9x?xf32>>, !fir.shapeshift<2>) -> !fir.box<!fir.array<9x?xf32>>
47 ! CHECK: %[[VAL_4:.*]] = fir.address_of(
48 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (!fir.box<!fir.array<9x?xf32>>) -> !fir.box<none>
49 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_1]] : (i64) -> i32
50 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]]
51 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranALboundDim(%[[VAL_5]], %[[VAL_6]], %[[VAL_7]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
52 ! CHECK: fir.store %[[VAL_8]] to %arg2 : !fir.ref<i64>
53 res
= lbound(a
, dim
, 8)
56 ! CHECK-LABEL: func @_QPlbound_test_4(
57 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<?x?xf32>> {fir.bindc_name = "a"},
58 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i64> {fir.bindc_name = "dim"},
59 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i64> {fir.bindc_name = "l1"},
60 ! CHECK-SAME: %[[VAL_3:.*]]: !fir.ref<i64> {fir.bindc_name = "u1"},
61 ! CHECK-SAME: %[[VAL_4:.*]]: !fir.ref<i64> {fir.bindc_name = "l2"},
62 ! CHECK-SAME: %[[VAL_5:.*]]: !fir.ref<i64> {fir.bindc_name = "u2"}) {
63 subroutine lbound_test_4(a
, dim
, l1
, u1
, l2
, u2
)
64 integer(8):: dim
, l1
, u1
, l2
, u2
65 ! CHECK: %[[VAL_6:.*]] = fir.alloca !fir.array<2xi32>
66 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_2]] : !fir.ref<i64>
67 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index
68 ! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_4]] : !fir.ref<i64>
69 ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i64) -> index
70 real, dimension(l1
:u1
, l2
:u2
) :: a
71 ! BeginExternalListOutput
72 ! CHECK: %[[VAL_32:.*]] = arith.constant 1 : i32
73 ! CHECK: %[[VAL_33:.*]] = arith.constant 0 : index
74 ! CHECK: %[[VAL_34:.*]] = arith.cmpi eq, %[[VAL_16:.*]], %[[VAL_33]] : index
75 ! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_32]] : (i32) -> index
76 ! CHECK: %[[VAL_36:.*]] = arith.select %[[VAL_34]], %[[VAL_35]], %[[VAL_8]] : index
77 ! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_36]] : (index) -> i32
78 ! CHECK: %[[VAL_38:.*]] = arith.constant 0 : index
79 ! CHECK: %[[VAL_39:.*]] = fir.coordinate_of %[[VAL_6]], %[[VAL_38]] : (!fir.ref<!fir.array<2xi32>>, index) -> !fir.ref<i32>
80 ! CHECK: fir.store %[[VAL_37]] to %[[VAL_39]] : !fir.ref<i32>
81 ! CHECK: %[[VAL_40:.*]] = arith.cmpi eq, %[[VAL_26:.*]], %[[VAL_33]] : index
82 ! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_32]] : (i32) -> index
83 ! CHECK: %[[VAL_42:.*]] = arith.select %[[VAL_40]], %[[VAL_41]], %[[VAL_18]] : index
84 ! CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_42]] : (index) -> i32
85 ! CHECK: %[[VAL_44:.*]] = arith.constant 1 : index
86 ! CHECK: %[[VAL_45:.*]] = fir.coordinate_of %[[VAL_6]], %[[VAL_44]] : (!fir.ref<!fir.array<2xi32>>, index) -> !fir.ref<i32>
87 ! CHECK: fir.store %[[VAL_43]] to %[[VAL_45]] : !fir.ref<i32>
88 ! CHECK: %[[VAL_46:.*]] = arith.constant 2 : index
89 ! CHECK: %[[VAL_47:.*]] = fir.shape %[[VAL_46]] : (index) -> !fir.shape<1>
90 ! CHECK: %[[VAL_48:.*]] = fir.embox %[[VAL_6]](%[[VAL_47]]) : (!fir.ref<!fir.array<2xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<2xi32>>
91 ! CHECK: %[[VAL_49:.*]] = fir.convert %[[VAL_48]] : (!fir.box<!fir.array<2xi32>>) -> !fir.box<none>
92 ! CHECK: fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[VAL_49]]) {{.*}}: (!fir.ref<i8>, !fir.box<none>) -> i1
93 print *, lbound(a
, kind
=4)