1 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
3 ! Test assumed shape dummy argument on callee side
5 ! TODO: These tests rely on looking at how a new fir.box is made for an assumed shape
6 ! to see if lowering lowered and mapped the assumed shape symbol properties.
7 ! However, the argument fir.box of the assumed shape could also be used instead
8 ! of making a new fir.box and this would break all these tests. In fact, for non
9 ! contiguous arrays, this is the case. Find a better way to tests symbol lowering/mapping.
11 ! CHECK-LABEL: func @_QPtest_assumed_shape_1(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "x", fir.contiguous})
12 subroutine test_assumed_shape_1(x
)
13 integer, contiguous
:: x(:)
14 ! CHECK: %[[addr:.*]] = fir.box_addr %arg0 : (!fir.box<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>>
15 ! CHECK: %[[c0:.*]] = arith.constant 0 : index
16 ! CHECK: %[[dims:.*]]:3 = fir.box_dims %arg0, %[[c0]] : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
17 ! CHECK: %[[c1:.*]] = arith.constant 1 : index
20 ! Test extent/lower bound use in the IO statement
21 ! CHECK: %[[cookie:.*]] = fir.call @_FortranAioBeginExternalListOutput
22 ! CHECK: %[[shape:.*]] = fir.shape_shift %[[c1]], %[[dims]]#1 : (index, index) -> !fir.shapeshift<1>
23 ! CHECK: %[[newbox:.*]] = fir.embox %[[addr]](%[[shape]]) : (!fir.ref<!fir.array<?xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xi32>>
24 ! CHECK: %[[castedBox:.*]] = fir.convert %[[newbox]] : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none>
25 ! CHECK: fir.call @_FortranAioOutputDescriptor(%[[cookie]], %[[castedBox]]) {{.*}}: (!fir.ref<i8>, !fir.box<none>) -> i1
28 ! lower bounds all ones
29 ! CHECK-LABEL: func @_QPtest_assumed_shape_2(%arg0: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x", fir.contiguous})
30 subroutine test_assumed_shape_2(x
)
31 real, contiguous
:: x(1:, 1:)
33 ! CHECK: %[[dims1:.*]]:3 = fir.box_dims
34 ! CHECK: %[[dims2:.*]]:3 = fir.box_dims
36 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
37 ! CHECK: fir.shape %[[dims1]]#1, %[[dims2]]#1
40 ! explicit lower bounds different from 1
41 ! CHECK-LABEL: func @_QPtest_assumed_shape_3(%arg0: !fir.box<!fir.array<?x?x?xi32>> {fir.bindc_name = "x", fir.contiguous})
42 subroutine test_assumed_shape_3(x
)
43 integer, contiguous
:: x(2:, 3:, 42:)
46 ! CHECK: %[[c2_i64:.*]] = arith.constant 2 : i64
47 ! CHECK: %[[c2:.*]] = fir.convert %[[c2_i64]] : (i64) -> index
49 ! CHECK: %[[c3_i64:.*]] = arith.constant 3 : i64
50 ! CHECK: %[[c3:.*]] = fir.convert %[[c3_i64]] : (i64) -> index
52 ! CHECK: %[[c42_i64:.*]] = arith.constant 42 : i64
53 ! CHECK: %[[c42:.*]] = fir.convert %[[c42_i64]] : (i64) -> index
56 ! CHECK: fir.shape_shift %[[c2]], %{{.*}}, %[[c3]], %{{.*}}, %[[c42]], %{{.*}} :
60 ! func @_QPtest_assumed_shape_char(%arg0: !fir.box<!fir.array<?x!fir.char<1,10>>> {fir.bindc_name = "c", fir.contiguous})
61 subroutine test_assumed_shape_char(c
)
62 character(10), contiguous
:: c(:)
63 ! CHECK: %[[addr:.*]] = fir.box_addr %arg0 : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.ref<!fir.array<?x!fir.char<1,10>>>
65 ! CHECK: %[[dims:.*]]:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index)
66 ! CHECK: %[[c1:.*]] = arith.constant 1 : index
69 ! CHECK: %[[shape:.*]] = fir.shape_shift %[[c1]], %[[dims]]#1 : (index, index) -> !fir.shapeshift<1>
70 ! CHECK: fir.embox %[[addr]](%[[shape]]) : (!fir.ref<!fir.array<?x!fir.char<1,10>>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?x!fir.char<1,10>>>
74 ! CHECK-LABEL: func @_QPtest_assumed_shape_char_2(%arg0: !fir.box<!fir.array<?x!fir.char<1,?>>> {fir.bindc_name = "c", fir.contiguous})
75 subroutine test_assumed_shape_char_2(c
)
76 character(*), contiguous
:: c(:)
77 ! CHECK: %[[addr:.*]] = fir.box_addr %arg0 : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> !fir.ref<!fir.array<?x!fir.char<1,?>>>
78 ! CHECK: %[[len:.*]] = fir.box_elesize %arg0 : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> index
80 ! CHECK: %[[dims:.*]]:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index) -> (index, index, index)
81 ! CHECK: %[[c1:.*]] = arith.constant 1 : index
84 ! CHECK: %[[shape:.*]] = fir.shape_shift %[[c1]], %[[dims]]#1 : (index, index) -> !fir.shapeshift<1>
85 ! CHECK: fir.embox %[[addr]](%[[shape]]) typeparams %[[len]] : (!fir.ref<!fir.array<?x!fir.char<1,?>>>, !fir.shapeshift<1>, index) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
90 ! CHECK: func @_QPtest_assumed_shape_char_3(%arg0: !fir.box<!fir.array<?x?x!fir.char<1,?>>> {fir.bindc_name = "c", fir.contiguous})
91 subroutine test_assumed_shape_char_3(c
)
92 character(*), contiguous
:: c(1:, 1:)
94 ! CHECK: fir.box_elesize
95 ! CHECK: %[[dims1:.*]]:3 = fir.box_dims
96 ! CHECK: %[[dims2:.*]]:3 = fir.box_dims
98 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
99 ! CHECK: fir.shape %[[dims1]]#1, %[[dims2]]#1