[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / Intrinsics / associated.f90
blob7fee5311152e29e3d13822eca7bee86f70522deb
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! CHECK-LABEL: associated_test
4 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.ptr<f32>>>{{.*}}, %[[arg1:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>{{.*}})
5 subroutine associated_test(scalar, array)
6 real, pointer :: scalar, array(:)
7 real, target :: ziel
8 ! CHECK: %[[ziel:.*]] = fir.alloca f32 {bindc_name = "ziel"
9 ! CHECK: %[[scalar:.*]] = fir.load %[[arg0]] : !fir.ref<!fir.box<!fir.ptr<f32>>>
10 ! CHECK: %[[addr0:.*]] = fir.box_addr %[[scalar]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>
11 ! CHECK: %[[addrToInt0:.*]] = fir.convert %[[addr0]]
12 ! CHECK: cmpi ne, %[[addrToInt0]], %c0{{.*}}
13 print *, associated(scalar)
14 ! CHECK: %[[array:.*]] = fir.load %[[arg1]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
15 ! CHECK: %[[addr1:.*]] = fir.box_addr %[[array]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
16 ! CHECK: %[[addrToInt1:.*]] = fir.convert %[[addr1]]
17 ! CHECK: cmpi ne, %[[addrToInt1]], %c0{{.*}}
18 print *, associated(array)
19 ! CHECK: %[[zbox0:.*]] = fir.embox %[[ziel]] : (!fir.ref<f32>) -> !fir.box<f32>
20 ! CHECK: %[[scalar:.*]] = fir.load %[[arg0]] : !fir.ref<!fir.box<!fir.ptr<f32>>>
21 ! CHECK: %[[sbox:.*]] = fir.convert %[[scalar]] : (!fir.box<!fir.ptr<f32>>) -> !fir.box<none>
22 ! CHECK: %[[zbox:.*]] = fir.convert %[[zbox0]] : (!fir.box<f32>) -> !fir.box<none>
23 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[sbox]], %[[zbox]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
24 print *, associated(scalar, ziel)
25 end subroutine
27 subroutine test_func_results()
28 interface
29 function get_pointer()
30 real, pointer :: get_pointer(:)
31 end function
32 end interface
33 ! CHECK: %[[result:.*]] = fir.call @_QPget_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
34 ! CHECK: fir.save_result %[[result]] to %[[box_storage:.*]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
35 ! CHECK: %[[box:.*]] = fir.load %[[box_storage]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
36 ! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.ptr<!fir.array<?xf32>>
37 ! CHECK: %[[addr_cast:.*]] = fir.convert %[[addr]] : (!fir.ptr<!fir.array<?xf32>>) -> i64
38 ! CHECK: arith.cmpi ne, %[[addr_cast]], %c0{{.*}} : i64
39 print *, associated(get_pointer())
40 end subroutine
42 ! CHECK-LABEL: func @_QPtest_optional_target_1(
43 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"},
44 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.array<10xf32>> {fir.bindc_name = "optionales_ziel", fir.optional, fir.target}) {
45 subroutine test_optional_target_1(p, optionales_ziel)
46 real, pointer :: p(:)
47 real, optional, target :: optionales_ziel(10)
48 print *, associated(p, optionales_ziel)
49 ! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index
50 ! CHECK: %[[VAL_3:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<!fir.array<10xf32>>) -> i1
51 ! CHECK: %[[VAL_4:.*]] = fir.if %[[VAL_3]] -> (!fir.box<none>) {
52 ! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
53 ! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_1]](%[[VAL_5]]) : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<10xf32>>
54 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (!fir.box<!fir.array<10xf32>>) -> !fir.box<none>
55 ! CHECK: fir.result %[[VAL_7]] : !fir.box<none>
56 ! CHECK: } else {
57 ! CHECK: %[[VAL_8:.*]] = fir.absent !fir.box<none>
58 ! CHECK: fir.result %[[VAL_8]] : !fir.box<none>
59 ! CHECK: }
60 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
61 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
62 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[VAL_14]], %[[VAL_4]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
63 end subroutine
65 ! CHECK-LABEL: func @_QPtest_optional_target_2(
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"},
67 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "optionales_ziel", fir.optional, fir.target}) {
68 subroutine test_optional_target_2(p, optionales_ziel)
69 real, pointer :: p(:)
70 real, optional, target :: optionales_ziel(:)
71 print *, associated(p, optionales_ziel)
72 ! CHECK: %[[VAL_7:.*]] = fir.is_present %[[VAL_1]] : (!fir.box<!fir.array<?xf32>>) -> i1
73 ! CHECK: %[[VAL_8:.*]] = fir.if %[[VAL_7]] -> (!fir.box<none>) {
74 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_1]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
75 ! CHECK: fir.result %[[VAL_9]] : !fir.box<none>
76 ! CHECK: } else {
77 ! CHECK: %[[VAL_10:.*]] = fir.absent !fir.box<none>
78 ! CHECK: fir.result %[[VAL_10]] : !fir.box<none>
79 ! CHECK: }
80 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
81 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
82 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[VAL_11]], %[[VAL_8]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
83 end subroutine
85 ! CHECK-LABEL: func @_QPtest_optional_target_3(
86 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"},
87 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "optionales_ziel", fir.optional}) {
88 subroutine test_optional_target_3(p, optionales_ziel)
89 real, pointer :: p(:)
90 real, optional, pointer :: optionales_ziel(:)
91 print *, associated(p, optionales_ziel)
92 ! CHECK: %[[VAL_8:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>) -> i1
93 ! CHECK: %[[VAL_9:.*]] = fir.if %[[VAL_8]] -> (!fir.box<none>) {
94 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
95 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
96 ! CHECK: fir.result %[[VAL_11]] : !fir.box<none>
97 ! CHECK: } else {
98 ! CHECK: %[[VAL_12:.*]] = fir.absent !fir.box<none>
99 ! CHECK: fir.result %[[VAL_12]] : !fir.box<none>
100 ! CHECK: }
101 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
102 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
103 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[VAL_12]], %[[VAL_9]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
104 end subroutine
106 ! CHECK-LABEL: func @_QPtest_optional_target_4(
107 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"},
108 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {fir.bindc_name = "optionales_ziel", fir.optional, fir.target}) {
109 subroutine test_optional_target_4(p, optionales_ziel)
110 real, pointer :: p(:)
111 real, optional, allocatable, target :: optionales_ziel(:)
112 print *, associated(p, optionales_ziel)
113 ! CHECK: %[[VAL_8:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> i1
114 ! CHECK: %[[VAL_9:.*]] = fir.if %[[VAL_8]] -> (!fir.box<none>) {
115 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
116 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.box<none>
117 ! CHECK: fir.result %[[VAL_11]] : !fir.box<none>
118 ! CHECK: } else {
119 ! CHECK: %[[VAL_12:.*]] = fir.absent !fir.box<none>
120 ! CHECK: fir.result %[[VAL_12]] : !fir.box<none>
121 ! CHECK: }
122 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
123 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
124 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[VAL_12]], %[[VAL_9]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
125 end subroutine
127 ! CHECK-LABEL: func @_QPtest_pointer_target(
128 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"},
129 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "pointer_ziel"}) {
130 subroutine test_pointer_target(p, pointer_ziel)
131 real, pointer :: p(:)
132 real, pointer :: pointer_ziel(:)
133 print *, associated(p, pointer_ziel)
134 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
135 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
136 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
137 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_7]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
138 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[VAL_9]], %[[VAL_10]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
139 end subroutine
141 ! CHECK-LABEL: func @_QPtest_allocatable_target(
142 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"},
143 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {fir.bindc_name = "allocatable_ziel", fir.target}) {
144 subroutine test_allocatable_target(p, allocatable_ziel)
145 real, pointer :: p(:)
146 real, allocatable, target :: allocatable_ziel(:)
147 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
148 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
149 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.box<none>
150 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_7]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.box<none>
151 ! CHECK: fir.call @_FortranAPointerIsAssociatedWith(%[[VAL_9]], %[[VAL_10]]) {{.*}}: (!fir.box<none>, !fir.box<none>) -> i1
152 print *, associated(p, allocatable_ziel)
153 end subroutine