| 1 |
! Test copy-in / copy-out of non-contiguous variable passed as F77 array arguments. |
| 2 |
! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s |
| 3 |
|
| 4 |
! Nominal test |
| 5 |
! CHECK-LABEL: func @_QPtest_assumed_shape_to_array( |
| 6 |
! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) { |
| 7 |
subroutine test_assumed_shape_to_array(x) |
| 8 |
real :: x(:) |
| 9 |
|
| 10 |
! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 11 |
! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1 |
| 12 |
! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] -> (!fir.heap<!fir.array<?xf32>>) { |
| 13 |
! CHECK: %[[box_addr:.*]] = fir.box_addr %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>> |
| 14 |
! CHECK: fir.result %[[box_addr]] : !fir.heap<!fir.array<?xf32>> |
| 15 |
! CHECK: } else { |
| 16 |
! Creating temp |
| 17 |
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x:.*]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 18 |
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 {uniq_name = ".copyinout"} |
| 19 |
|
| 20 |
! Copy-in |
| 21 |
! CHECK-DAG: %[[shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1> |
| 22 |
! CHECK-DAG: %[[temp_box:.*]] = fir.embox %[[temp]](%[[shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 23 |
! CHECK-DAG: fir.store %[[temp_box]] to %[[temp_box_loc:.*]] : !fir.ref<!fir.box<!fir.array<?xf32>>> |
| 24 |
! CHECK-DAG: %[[temp_box_addr:.*]] = fir.convert %[[temp_box_loc]] : (!fir.ref<!fir.box<!fir.array<?xf32>>>) -> !fir.ref<!fir.box<none>> |
| 25 |
! CHECK-DAG: %[[arg_box:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 26 |
! CHECK-DAG: fir.call @_FortranAAssignTemporary(%[[temp_box_addr]], %[[arg_box]], %{{.*}}, %{{.*}}){{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 27 |
! CHECK: fir.result %[[temp]] : !fir.heap<!fir.array<?xf32>> |
| 28 |
|
| 29 |
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 30 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> |
| 31 |
! CHECK: fir.call @_QPbar(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> () |
| 32 |
|
| 33 |
! Copy-out |
| 34 |
! CHECK-DAG: %[[shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1> |
| 35 |
! CHECK-DAG: %[[temp_box:.*]] = fir.embox %[[addr]](%[[shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 36 |
! CHECK: %[[rebox:.*]] = fir.rebox %[[temp_box]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.heap<!fir.array<?xf32>>> |
| 37 |
! CHECK: fir.store %[[rebox]] to %[[temp_box_ref:.*]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> |
| 38 |
! CHECK-DAG: fir.store %[[x]] to %[[arg_box_loc:.*]] : !fir.ref<!fir.box<!fir.array<?xf32>>> |
| 39 |
! CHECK-DAG: %[[arg_box_addr:.*]] = fir.convert %[[arg_box_loc]] : (!fir.ref<!fir.box<!fir.array<?xf32>>>) -> !fir.ref<!fir.box<none>> |
| 40 |
! CHECK-DAG: %[[temp_box_cast:.*]] = fir.convert %[[temp_box_ref]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> !fir.ref<!fir.box<none>> |
| 41 |
! CHECK-DAG: fir.call @_FortranACopyOutAssign(%[[arg_box_addr]], %[[temp_box_cast]], %{{.*}}, %{{.*}}){{.*}}: (!fir.ref<!fir.box<none>>, !fir.ref<!fir.box<none>>, !fir.ref<i8>, i32) -> none |
| 42 |
|
| 43 |
call bar(x) |
| 44 |
end subroutine |
| 45 |
|
| 46 |
! Test that copy-in/copy-out does not trigger the re-evaluation of |
| 47 |
! the designator expression. |
| 48 |
! CHECK-LABEL: func @_QPeval_expr_only_once( |
| 49 |
! CHECK-SAME: %[[x:.*]]: !fir.ref<!fir.array<200xf32>>{{.*}}) { |
| 50 |
subroutine eval_expr_only_once(x) |
| 51 |
integer :: only_once |
| 52 |
real :: x(200) |
| 53 |
! CHECK: fir.call @_QPonly_once() |
| 54 |
! CHECK: %[[x_section:.*]] = fir.embox %[[x]](%{{.*}}) [%{{.*}}] : (!fir.ref<!fir.array<200xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>> |
| 55 |
! CHECK: %[[box_none:.*]] = fir.convert %[[x_section]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 56 |
! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1 |
| 57 |
! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] -> (!fir.heap<!fir.array<?xf32>>) { |
| 58 |
|
| 59 |
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32> |
| 60 |
! CHECK-NOT: fir.call @_QPonly_once() |
| 61 |
! CHECK: fir.call @_FortranAAssignTemporary |
| 62 |
! CHECK-NOT: fir.call @_QPonly_once() |
| 63 |
|
| 64 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> |
| 65 |
! CHECK: fir.call @_QPbar(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> () |
| 66 |
call bar(x(1:200:only_once())) |
| 67 |
|
| 68 |
! CHECK-NOT: fir.call @_QPonly_once() |
| 69 |
! CHECK: fir.call @_FortranACopyOutAssign |
| 70 |
! CHECK-NOT: fir.call @_QPonly_once() |
| 71 |
|
| 72 |
end subroutine |
| 73 |
|
| 74 |
! Test no copy-in/copy-out is generated for contiguous assumed shapes. |
| 75 |
! CHECK-LABEL: func @_QPtest_contiguous( |
| 76 |
! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>> |
| 77 |
subroutine test_contiguous(x) |
| 78 |
real, contiguous :: x(:) |
| 79 |
! CHECK: %[[addr:.*]] = fir.box_addr %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> |
| 80 |
! CHECK-NOT: fir.call @_FortranAAssignTemporary |
| 81 |
! CHECK: fir.call @_QPbar(%[[addr]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> () |
| 82 |
call bar(x) |
| 83 |
! CHECK-NOT: fir.call @_FortranACopyOutAssign |
| 84 |
! CHECK: return |
| 85 |
end subroutine |
| 86 |
|
| 87 |
! Test the parenthesis are preventing copy-out. |
| 88 |
! CHECK: func @_QPtest_parenthesis( |
| 89 |
! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) { |
| 90 |
subroutine test_parenthesis(x) |
| 91 |
real :: x(:) |
| 92 |
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 93 |
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 {uniq_name = ".array.expr"} |
| 94 |
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[temp]] |
| 95 |
! CHECK: %[[cast:.*]] = fir.convert %[[temp]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> |
| 96 |
! CHECK: fir.call @_QPbar(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> () |
| 97 |
call bar((x)) |
| 98 |
! CHECK-NOT: fir.call @_FortranACopyOutAssign |
| 99 |
! CHECK: return |
| 100 |
end subroutine |
| 101 |
|
| 102 |
! Test copy-in in is skipped for intent(out) arguments. |
| 103 |
! CHECK: func @_QPtest_intent_out( |
| 104 |
! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) { |
| 105 |
subroutine test_intent_out(x) |
| 106 |
real :: x(:) |
| 107 |
interface |
| 108 |
subroutine bar_intent_out(x) |
| 109 |
real, intent(out) :: x(100) |
| 110 |
end subroutine |
| 111 |
end interface |
| 112 |
! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 113 |
! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1 |
| 114 |
! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] |
| 115 |
! CHECK: } else { |
| 116 |
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 117 |
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 |
| 118 |
! CHECK-NOT: fir.call @_FortranAAssignTemporary |
| 119 |
! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1 |
| 120 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>> |
| 121 |
! CHECK: fir.call @_QPbar_intent_out(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xf32>>) -> () |
| 122 |
call bar_intent_out(x) |
| 123 |
|
| 124 |
! CHECK: fir.if %[[not_contiguous]] |
| 125 |
! CHECK: fir.call @_FortranACopyOutAssign |
| 126 |
! CHECK: return |
| 127 |
end subroutine |
| 128 |
|
| 129 |
! Test copy-out is skipped for intent(out) arguments. |
| 130 |
! CHECK-LABEL: func.func @_QPtest_intent_in( |
| 131 |
! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) { |
| 132 |
subroutine test_intent_in(x) |
| 133 |
real :: x(:) |
| 134 |
interface |
| 135 |
subroutine bar_intent_in(x) |
| 136 |
real, intent(in) :: x(100) |
| 137 |
end subroutine |
| 138 |
end interface |
| 139 |
! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 140 |
! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1 |
| 141 |
! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] |
| 142 |
! CHECK: } else { |
| 143 |
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 144 |
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 |
| 145 |
! CHECK: %[[temp_shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1> |
| 146 |
! CHECK: %[[temp_box:.*]] = fir.embox %[[temp]](%[[temp_shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 147 |
! CHECK: fir.store %[[temp_box]] to %[[temp_box_loc:.*]] : !fir.ref<!fir.box<!fir.array<?xf32>>> |
| 148 |
! CHECK: %[[temp_box_addr:.*]] = fir.convert %[[temp_box_loc]] : (!fir.ref<!fir.box<!fir.array<?xf32>>>) -> !fir.ref<!fir.box<none>> |
| 149 |
! CHECK: fir.call @_FortranAAssignTemporary(%[[temp_box_addr]], |
| 150 |
! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1 |
| 151 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>> |
| 152 |
! CHECK: fir.call @_QPbar_intent_in(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xf32>>) -> () |
| 153 |
call bar_intent_in(x) |
| 154 |
! CHECK: fir.if %[[not_contiguous]] |
| 155 |
! CHECK: fir.zero |
| 156 |
! CHECK: fir.call @_FortranACopyOutAssign |
| 157 |
! CHECK: return |
| 158 |
end subroutine |
| 159 |
|
| 160 |
! Test copy-in/copy-out is done for intent(inout) |
| 161 |
! CHECK: func @_QPtest_intent_inout( |
| 162 |
! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) { |
| 163 |
subroutine test_intent_inout(x) |
| 164 |
real :: x(:) |
| 165 |
interface |
| 166 |
subroutine bar_intent_inout(x) |
| 167 |
real, intent(inout) :: x(100) |
| 168 |
end subroutine |
| 169 |
end interface |
| 170 |
! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 171 |
! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) {{.*}}: (!fir.box<none>) -> i1 |
| 172 |
! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] |
| 173 |
! CHECK: } else { |
| 174 |
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 175 |
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 |
| 176 |
! CHECK: fir.call @_FortranAAssign |
| 177 |
! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1 |
| 178 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>> |
| 179 |
! CHECK: fir.call @_QPbar_intent_inout(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xf32>>) -> () |
| 180 |
call bar_intent_inout(x) |
| 181 |
! CHECK: fir.if %[[not_contiguous]] |
| 182 |
! CHECK: fir.call @_FortranACopyOutAssign |
| 183 |
! CHECK: return |
| 184 |
end subroutine |
| 185 |
|
| 186 |
! Test characters are handled correctly |
| 187 |
! CHECK-LABEL: func @_QPtest_char( |
| 188 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.char<1,10>>>{{.*}}) { |
| 189 |
subroutine test_char(x) |
| 190 |
! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.array<?x!fir.char<1,10>>> |
| 191 |
! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box<!fir.array<?x!fir.char<1,10>>> |
| 192 |
! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index |
| 193 |
! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<none> |
| 194 |
! CHECK: %[[VAL_5:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_4]]) fastmath<contract> : (!fir.box<none>) -> i1 |
| 195 |
! CHECK: %[[VAL_6:.*]] = fir.if %[[VAL_5]] -> (!fir.heap<!fir.array<?x!fir.char<1,10>>>) { |
| 196 |
! CHECK: %[[VAL_7:.*]] = fir.box_addr %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.heap<!fir.array<?x!fir.char<1,10>>> |
| 197 |
! CHECK: fir.result %[[VAL_7]] : !fir.heap<!fir.array<?x!fir.char<1,10>>> |
| 198 |
! CHECK: } else { |
| 199 |
! CHECK: %[[VAL_8:.*]] = arith.constant 0 : index |
| 200 |
! CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_8]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index) |
| 201 |
! CHECK: %[[VAL_10:.*]] = fir.allocmem !fir.array<?x!fir.char<1,10>>, %[[VAL_9]]#1 {uniq_name = ".copyinout"} |
| 202 |
! CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_9]]#1 : (index) -> !fir.shape<1> |
| 203 |
! CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_10]](%[[VAL_11]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.char<1,10>>> |
| 204 |
! CHECK: fir.store %[[VAL_12]] to %[[VAL_2]] : !fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>> |
| 205 |
! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>>) -> !fir.ref<!fir.box<none>> |
| 206 |
! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<none> |
| 207 |
! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAAssignTemporary(%[[VAL_15]], %[[VAL_16]], %{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 208 |
! CHECK: fir.result %[[VAL_10]] : !fir.heap<!fir.array<?x!fir.char<1,10>>> |
| 209 |
! CHECK: } |
| 210 |
! CHECK: %[[VAL_19:.*]] = arith.constant 0 : index |
| 211 |
! CHECK: %[[VAL_20:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_19]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index) |
| 212 |
! CHECK: %[[VAL_21:.*]] = arith.constant false |
| 213 |
! CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_5]], %[[VAL_21]] : i1 |
| 214 |
! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_24:.*]] : (!fir.heap<!fir.array<?x!fir.char<1,10>>>) -> !fir.ref<!fir.char<1,?>> |
| 215 |
! CHECK: %[[VAL_25:.*]] = fir.emboxchar %[[VAL_23]], %[[VAL_3]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1> |
| 216 |
! CHECK: fir.call @_QPbar_char(%[[VAL_25]]) fastmath<contract> : (!fir.boxchar<1>) -> () |
| 217 |
! CHECK: fir.if %[[VAL_22]] { |
| 218 |
! CHECK: %[[VAL_26:.*]] = fir.shape %[[VAL_20]]#1 : (index) -> !fir.shape<1> |
| 219 |
! CHECK: %[[VAL_27:.*]] = fir.embox %[[VAL_24]](%[[VAL_26]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.char<1,10>>> |
| 220 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[VAL_27]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>> |
| 221 |
! CHECK: fir.store %[[REBOX]] to %[[TMP_BOX_REF:.*]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>> |
| 222 |
! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>> |
| 223 |
! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.box<!fir.array<?x!fir.char<1,10>>>>) -> !fir.ref<!fir.box<none>> |
| 224 |
! CHECK: %[[VAL_32:.*]] = fir.convert %[[TMP_BOX_REF]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>) -> !fir.ref<!fir.box<none>> |
| 225 |
! CHECK: %[[VAL_34:.*]] = fir.call @_FortranACopyOutAssign(%[[VAL_31]], %[[VAL_32]], %{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.ref<!fir.box<none>>, !fir.ref<i8>, i32) -> none |
| 226 |
! CHECK: } |
| 227 |
|
| 228 |
character(10) :: x(:) |
| 229 |
call bar_char(x) |
| 230 |
! CHECK: return |
| 231 |
! CHECK: } |
| 232 |
end subroutine test_char |
| 233 |
|
| 234 |
! CHECK-LABEL: func @_QPtest_scalar_substring_does_no_trigger_copy_inout |
| 235 |
! CHECK-SAME: %[[arg0:.*]]: !fir.boxchar<1> |
| 236 |
subroutine test_scalar_substring_does_no_trigger_copy_inout(c, i, j) |
| 237 |
character(*) :: c |
| 238 |
integer :: i, j |
| 239 |
! CHECK: %[[unbox:.*]]:2 = fir.unboxchar %[[arg0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index) |
| 240 |
! CHECK: %[[c:.*]] = fir.convert %[[unbox]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<?x!fir.char<1>>> |
| 241 |
! CHECK: %[[coor:.*]] = fir.coordinate_of %[[c]], %{{.*}} : (!fir.ref<!fir.array<?x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>> |
| 242 |
! CHECK: %[[substr:.*]] = fir.convert %[[coor]] : (!fir.ref<!fir.char<1>>) -> !fir.ref<!fir.char<1,?>> |
| 243 |
! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[substr]], %{{.*}} : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1> |
| 244 |
! CHECK: fir.call @_QPbar_char_2(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> () |
| 245 |
call bar_char_2(c(i:j)) |
| 246 |
end subroutine |
| 247 |
|
| 248 |
! CHECK-LABEL: func @_QPissue871( |
| 249 |
! CHECK-SAME: %[[p:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.type<_QFissue871Tt{i:i32}>>>>{{.*}}) |
| 250 |
subroutine issue871(p) |
| 251 |
! Test passing implicit derived from scalar pointer (no copy-in/out). |
| 252 |
type t |
| 253 |
integer :: i |
| 254 |
end type t |
| 255 |
type(t), pointer :: p |
| 256 |
! CHECK: %[[box_load:.*]] = fir.load %[[p]] |
| 257 |
! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]] |
| 258 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] |
| 259 |
! CHECK: fir.call @_QPbar_derived(%[[cast]]) |
| 260 |
call bar_derived(p) |
| 261 |
end subroutine |
| 262 |
|
| 263 |
! CHECK-LABEL: func @_QPissue871_array( |
| 264 |
! CHECK-SAME: %[[p:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QFissue871_arrayTt{i:i32}>>>>> |
| 265 |
subroutine issue871_array(p) |
| 266 |
! Test passing implicit derived from contiguous pointer (no copy-in/out). |
| 267 |
type t |
| 268 |
integer :: i |
| 269 |
end type t |
| 270 |
type(t), pointer, contiguous :: p(:) |
| 271 |
! CHECK: %[[box_load:.*]] = fir.load %[[p]] |
| 272 |
! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]] |
| 273 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] |
| 274 |
! CHECK: fir.call @_QPbar_derived_array(%[[cast]]) |
| 275 |
call bar_derived_array(p) |
| 276 |
end subroutine |
| 277 |
|
| 278 |
! CHECK-LABEL: func @_QPwhole_components() |
| 279 |
subroutine whole_components() |
| 280 |
! Test no copy is made for whole components. |
| 281 |
type t |
| 282 |
integer :: i(100) |
| 283 |
end type |
| 284 |
! CHECK: %[[a:.*]] = fir.alloca !fir.type<_QFwhole_componentsTt{i:!fir.array<100xi32>}> |
| 285 |
type(t) :: a |
| 286 |
! CHECK: %[[field:.*]] = fir.field_index i, !fir.type<_QFwhole_componentsTt{i:!fir.array<100xi32>}> |
| 287 |
! CHECK: %[[addr:.*]] = fir.coordinate_of %[[a]], %[[field]] : (!fir.ref<!fir.type<_QFwhole_componentsTt{i:!fir.array<100xi32>}>>, !fir.field) -> !fir.ref<!fir.array<100xi32>> |
| 288 |
! CHECK: fir.call @_QPbar_integer(%[[addr]]) {{.*}}: (!fir.ref<!fir.array<100xi32>>) -> () |
| 289 |
call bar_integer(a%i) |
| 290 |
end subroutine |
| 291 |
|
| 292 |
! CHECK-LABEL: func @_QPwhole_component_contiguous_pointer() |
| 293 |
subroutine whole_component_contiguous_pointer() |
| 294 |
! Test no copy is made for whole contiguous pointer components. |
| 295 |
type t |
| 296 |
integer, pointer, contiguous :: i(:) |
| 297 |
end type |
| 298 |
! CHECK: %[[a:.*]] = fir.alloca !fir.type<_QFwhole_component_contiguous_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?xi32>>>}> |
| 299 |
type(t) :: a |
| 300 |
! CHECK: %[[field:.*]] = fir.field_index i, !fir.type<_QFwhole_component_contiguous_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?xi32>>>}> |
| 301 |
! CHECK: %[[coor:.*]] = fir.coordinate_of %[[a]], %[[field]] : (!fir.ref<!fir.type<_QFwhole_component_contiguous_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> |
| 302 |
! CHECK: %[[box_load:.*]] = fir.load %[[coor]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> |
| 303 |
! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]] : (!fir.box<!fir.ptr<!fir.array<?xi32>>>) -> !fir.ptr<!fir.array<?xi32>> |
| 304 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.ptr<!fir.array<?xi32>>) -> !fir.ref<!fir.array<100xi32>> |
| 305 |
! CHECK: fir.call @_QPbar_integer(%[[cast]]) {{.*}}: (!fir.ref<!fir.array<100xi32>>) -> () |
| 306 |
call bar_integer(a%i) |
| 307 |
end subroutine |
| 308 |
|
| 309 |
! CHECK-LABEL: func @_QPwhole_component_contiguous_char_pointer() |
| 310 |
subroutine whole_component_contiguous_char_pointer() |
| 311 |
! Test no copy is made for whole contiguous character pointer components. |
| 312 |
type t |
| 313 |
character(:), pointer, contiguous :: i(:) |
| 314 |
end type |
| 315 |
! CHECK: %[[a:.*]] = fir.alloca !fir.type<_QFwhole_component_contiguous_char_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>}> |
| 316 |
type(t) :: a |
| 317 |
! CHECK: %[[field:.*]] = fir.field_index i, !fir.type<_QFwhole_component_contiguous_char_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>}> |
| 318 |
! CHECK: %[[coor:.*]] = fir.coordinate_of %[[a]], %[[field]] : (!fir.ref<!fir.type<_QFwhole_component_contiguous_char_pointerTt{i:!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>> |
| 319 |
! CHECK: %[[box_load:.*]] = fir.load %[[coor]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>> |
| 320 |
! CHECK: %[[addr:.*]] = fir.box_addr %[[box_load]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>) -> !fir.ptr<!fir.array<?x!fir.char<1,?>>> |
| 321 |
! CHECK: %[[len:.*]] = fir.box_elesize %[[box_load]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>) -> index |
| 322 |
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.ptr<!fir.array<?x!fir.char<1,?>>>) -> !fir.ref<!fir.char<1,?>> |
| 323 |
! CHECK: %[[embox:.*]] = fir.emboxchar %[[cast]], %[[len]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1> |
| 324 |
! CHECK: fir.call @_QPbar_char_3(%[[embox]]) {{.*}}: (!fir.boxchar<1>) -> () |
| 325 |
call bar_char_3(a%i) |
| 326 |
end subroutine |