Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / assumed-shape-callee.f90
blobe050a261701dc0b9ffbe80e99efb519e9bc411ec
1 ! RUN: bbc -emit-fir %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
19 print *, x
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
26 end subroutine
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:)
32 ! CHECK: fir.box_addr
33 ! CHECK: %[[dims1:.*]]:3 = fir.box_dims
34 ! CHECK: %[[dims2:.*]]:3 = fir.box_dims
35 print *, x
36 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
37 ! CHECK: fir.shape %[[dims1]]#1, %[[dims2]]#1
38 end subroutine
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:)
44 ! CHECK: fir.box_addr
45 ! CHECK: fir.box_dim
46 ! CHECK: %[[c2_i64:.*]] = arith.constant 2 : i64
47 ! CHECK: %[[c2:.*]] = fir.convert %[[c2_i64]] : (i64) -> index
48 ! CHECK: fir.box_dim
49 ! CHECK: %[[c3_i64:.*]] = arith.constant 3 : i64
50 ! CHECK: %[[c3:.*]] = fir.convert %[[c3_i64]] : (i64) -> index
51 ! CHECK: fir.box_dim
52 ! CHECK: %[[c42_i64:.*]] = arith.constant 42 : i64
53 ! CHECK: %[[c42:.*]] = fir.convert %[[c42_i64]] : (i64) -> index
55 print *, x
56 ! CHECK: fir.shape_shift %[[c2]], %{{.*}}, %[[c3]], %{{.*}}, %[[c42]], %{{.*}} :
57 end subroutine
59 ! Constant length
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
68 print *, c
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>>>
71 end subroutine
73 ! Assumed length
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
83 print *, c
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,?>>>
86 end subroutine
89 ! lower bounds all 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:)
93 ! CHECK: fir.box_addr
94 ! CHECK: fir.box_elesize
95 ! CHECK: %[[dims1:.*]]:3 = fir.box_dims
96 ! CHECK: %[[dims2:.*]]:3 = fir.box_dims
97 print *, c
98 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
99 ! CHECK: fir.shape %[[dims1]]#1, %[[dims2]]#1
100 end subroutine