1 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s
4 ! CHECK-LABEL: func @_QPubound_test(
5 subroutine ubound_test(a
, dim
, res
)
6 real, dimension(:, :) :: a
8 ! CHECK: %[[VAL_0:.*]] = fir.load
9 ! CHECK: %[[VAL_1:.*]] = fir.address_of(
10 ! CHECK: %[[VAL_2:.*]] = fir.convert
11 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32
12 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]]
13 ! CHECK: %[[VAL_5:.*]] = fir.call @_FortranASizeDim(%[[VAL_2]], %[[VAL_3]], %[[VAL_4]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
14 ! CHECK: %[[VAL_6:.*]] = fir.address_of(
15 ! CHECK: %[[VAL_7:.*]] = fir.convert %{{.*}} : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
16 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32
17 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]]
18 ! CHECK: %[[VAL_10:.*]] = fir.call @_FortranALboundDim(%[[VAL_7]], %[[VAL_8]], %[[VAL_9]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
19 ! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %c1_i64 : i64
20 ! CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %[[VAL_5]] : i64
22 ! CHECK: fir.store %[[VAL_12]] to %{{.*}} : !fir.ref<i64>
23 res
= ubound(a
, dim
, 8)
26 ! CHECK-LABEL: func @_QPubound_test_2(
27 subroutine ubound_test_2(a
, dim
, res
)
28 real, dimension(2:, 3:) :: a
30 ! CHECK: %[[VAL_0:.*]] = fir.load %{{.*}} : !fir.ref<i64>
31 ! CHECK: %[[VAL_1:.*]] = fir.address_of(
32 ! CHECK: %[[VAL_2:.*]] = fir.convert %{{.*}} : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
33 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32
34 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]]
35 ! CHECK: %[[VAL_5:.*]] = fir.call @_FortranASizeDim(%[[VAL_2]], %[[VAL_3]], %[[VAL_4]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
36 ! CHECK: %[[VAL_6:.*]] = fir.address_of(
37 ! CHECK: %[[VAL_7:.*]] = fir.convert %{{.*}} : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
38 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32
39 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]]
40 ! CHECK: %[[VAL_10:.*]] = fir.call @_FortranALboundDim(%[[VAL_7]], %[[VAL_8]], %[[VAL_9]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
41 ! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %{{.*}} : i64
42 ! CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %[[VAL_5]] : i64
43 ! CHECK: fir.store %[[VAL_12]] to %{{.*}} : !fir.ref<i64>
44 res
= ubound(a
, dim
, 8)
47 ! CHECK-LABEL: func @_QPubound_test_3(
48 subroutine ubound_test_3(a
, dim
, res
)
49 real, dimension(10, 20, *) :: a
51 ! CHECK: %[[VAL_0:.*]] = arith.constant -1 : index
52 ! CHECK: %[[VAL_1:.*]] = fir.shape %{{.*}}, %{{.*}}, %[[VAL_0]] : (index, index, index) -> !fir.shape<3>
53 ! CHECK: %[[VAL_2:.*]] = fir.embox %{{.*}}(%[[VAL_1]]) : (!fir.ref<!fir.array<10x20x?xf32>>, !fir.shape<3>) -> !fir.box<!fir.array<10x20x?xf32>>
54 ! CHECK: %[[VAL_3:.*]] = fir.load %{{.*}} : !fir.ref<i64>
55 ! CHECK: %[[VAL_4:.*]] = fir.address_of(
56 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_2]] : (!fir.box<!fir.array<10x20x?xf32>>) -> !fir.box<none>
58 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_3]] : (i64) -> i32
59 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]]
60 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranASizeDim(%[[VAL_5]], %[[VAL_6]], %[[VAL_7]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
61 ! CHECK: %[[VAL_9:.*]] = fir.rebox %[[VAL_2]] : (!fir.box<!fir.array<10x20x?xf32>>) -> !fir.box<!fir.array<10x20x?xf32>>
62 ! CHECK: %[[VAL_10:.*]] = fir.address_of(
63 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_9]] : (!fir.box<!fir.array<10x20x?xf32>>) -> !fir.box<none>
64 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_3]]
65 ! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_10]]
66 ! CHECK: %[[VAL_14:.*]] = fir.call @_FortranALboundDim(%[[VAL_11]], %[[VAL_12]], %[[VAL_13]], %{{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
67 ! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %{{.*}} : i64
68 ! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_15]], %[[VAL_8]] : i64
69 ! CHECK: fir.store %[[VAL_16]] to %{{.*}} : !fir.ref<i64>
70 res
= ubound(a
, dim
, 8)
74 ! CHECK-LABEL: func @_QPubound_test_const_dim(
75 subroutine ubound_test_const_dim(array
)
78 ! Should not call _FortranASizeDim when dim is compile time constant. But instead load from descriptor directly.
79 ! CHECK: %[[C0:.*]] = arith.constant 0 : index
80 ! CHECK: %[[DIMS:.*]]:3 = fir.box_dims %arg0, %[[C0]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
81 ! CHECK: %{{.*}} = fir.convert %[[DIMS]]#1 : (index) -> i32
82 res
= ubound(array
, 1)