1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
|
! RUN: bbc -emit-fir %s -o - | FileCheck %s
module callee
implicit none
contains
! CHECK-LABEL: func @_QMcalleePreturn_cst_array() -> !fir.array<20x30xf32>
function return_cst_array()
real :: return_cst_array(20, 30)
end function
! CHECK-LABEL: func @_QMcalleePreturn_dyn_array(
! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<?x?xf32>
function return_dyn_array(m, n)
integer :: m, n
real :: return_dyn_array(m, n)
end function
! CHECK-LABEL: func @_QMcalleePreturn_cst_char_cst_array() -> !fir.array<20x30x!fir.char<1,10>>
function return_cst_char_cst_array()
character(10) :: return_cst_char_cst_array(20, 30)
end function
! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_cst_array(
! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<20x30x!fir.char<1,?>>
function return_dyn_char_cst_array(l)
integer :: l
character(l) :: return_dyn_char_cst_array(20, 30)
end function
! CHECK-LABEL: func @_QMcalleePreturn_cst_char_dyn_array(
! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<?x?x!fir.char<1,10>>
function return_cst_char_dyn_array(m, n)
integer :: m, n
character(10) :: return_cst_char_dyn_array(m, n)
end function
! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_dyn_array(
! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<?x?x!fir.char<1,?>>
function return_dyn_char_dyn_array(l, m, n)
integer :: l, m, n
character(l) :: return_dyn_char_dyn_array(m, n)
end function
! CHECK-LABEL: func @_QMcalleePreturn_alloc() -> !fir.box<!fir.heap<!fir.array<?xf32>>>
function return_alloc()
real, allocatable :: return_alloc(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_cst_char_alloc() -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
function return_cst_char_alloc()
character(10), allocatable :: return_cst_char_alloc(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_alloc(
! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
function return_dyn_char_alloc(l)
integer :: l
character(l), allocatable :: return_dyn_char_alloc(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_def_char_alloc() -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
function return_def_char_alloc()
character(:), allocatable :: return_def_char_alloc(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_pointer() -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
function return_pointer()
real, pointer :: return_pointer(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_cst_char_pointer() -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
function return_cst_char_pointer()
character(10), pointer :: return_cst_char_pointer(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_pointer(
! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
function return_dyn_char_pointer(l)
integer :: l
character(l), pointer :: return_dyn_char_pointer(:)
end function
! CHECK-LABEL: func @_QMcalleePreturn_def_char_pointer() -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
function return_def_char_pointer()
character(:), pointer :: return_def_char_pointer(:)
end function
end module
module caller
use callee
contains
! CHECK-LABEL: func @_QMcallerPcst_array()
subroutine cst_array()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.array<20x30xf32> {{{.*}}bindc_name = ".result"}
! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, {{.*}} : (index, index) -> !fir.shape<2>
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_array() {{.*}}: () -> !fir.array<20x30xf32>
! CHECK: fir.save_result %[[res]] to %[[alloc]](%[[shape]]) : !fir.array<20x30xf32>, !fir.ref<!fir.array<20x30xf32>>, !fir.shape<2>
print *, return_cst_array()
end subroutine
! CHECK-LABEL: func @_QMcallerPcst_char_cst_array()
subroutine cst_char_cst_array()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.array<20x30x!fir.char<1,10>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, {{.*}} : (index, index) -> !fir.shape<2>
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_cst_array() {{.*}}: () -> !fir.array<20x30x!fir.char<1,10>>
! CHECK: fir.save_result %[[res]] to %[[alloc]](%[[shape]]) typeparams %{{.*}} : !fir.array<20x30x!fir.char<1,10>>, !fir.ref<!fir.array<20x30x!fir.char<1,10>>>, !fir.shape<2>, index
print *, return_cst_char_cst_array()
end subroutine
! CHECK-LABEL: func @_QMcallerPalloc()
subroutine alloc()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?xf32>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
print *, return_alloc()
! CHECK: _FortranAioOutputDescriptor
! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
! CHECK: %[[cmpi:.*]] = arith.cmpi
! CHECK: fir.if %[[cmpi]]
! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
end subroutine
! CHECK-LABEL: func @_QMcallerPcst_char_alloc()
subroutine cst_char_alloc()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
print *, return_cst_char_alloc()
! CHECK: _FortranAioOutputDescriptor
! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,10>>>
! CHECK: %[[cmpi:.*]] = arith.cmpi
! CHECK: fir.if %[[cmpi]]
! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
end subroutine
! CHECK-LABEL: func @_QMcallerPdef_char_alloc()
subroutine def_char_alloc()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_def_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
print *, return_def_char_alloc()
! CHECK: _FortranAioOutputDescriptor
! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,?>>>
! CHECK: %[[cmpi:.*]] = arith.cmpi
! CHECK: fir.if %[[cmpi]]
! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,?>>>
end subroutine
! CHECK-LABEL: func @_QMcallerPpointer_test()
subroutine pointer_test()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
print *, return_pointer()
! CHECK-NOT: fir.freemem
end subroutine
! CHECK-LABEL: func @_QMcallerPcst_char_pointer()
subroutine cst_char_pointer()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>>
print *, return_cst_char_pointer()
! CHECK-NOT: fir.freemem
end subroutine
! CHECK-LABEL: func @_QMcallerPdef_char_pointer()
subroutine def_char_pointer()
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_def_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
print *, return_def_char_pointer()
! CHECK-NOT: fir.freemem
end subroutine
! CHECK-LABEL: func @_QMcallerPdyn_array(
! CHECK-SAME: %[[m:.*]]: !fir.ref<i32>{{.*}}, %[[n:.*]]: !fir.ref<i32>{{.*}}) {
subroutine dyn_array(m, n)
integer :: m, n
! CHECK-DAG: %[[mload:.*]] = fir.load %[[m]] : !fir.ref<i32>
! CHECK-DAG: %[[mcast:.*]] = fir.convert %[[mload]] : (i32) -> i64
! CHECK-DAG: %[[msub:.*]] = arith.subi %[[mcast]], %c1{{.*}} : i64
! CHECK-DAG: %[[madd:.*]] = arith.addi %[[msub]], %c1{{.*}} : i64
! CHECK-DAG: %[[mcast2:.*]] = fir.convert %[[madd]] : (i64) -> index
! CHECK-DAG: %[[mcmpi:.*]] = arith.cmpi sgt, %[[mcast2]], %{{.*}} : index
! CHECK-DAG: %[[mselect:.*]] = arith.select %[[mcmpi]], %[[mcast2]], %{{.*}} : index
! CHECK-DAG: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i32>
! CHECK-DAG: %[[ncast:.*]] = fir.convert %[[nload]] : (i32) -> i64
! CHECK-DAG: %[[nsub:.*]] = arith.subi %[[ncast]], %c1{{.*}} : i64
! CHECK-DAG: %[[nadd:.*]] = arith.addi %[[nsub]], %c1{{.*}} : i64
! CHECK-DAG: %[[ncast2:.*]] = fir.convert %[[nadd]] : (i64) -> index
! CHECK-DAG: %[[ncmpi:.*]] = arith.cmpi sgt, %[[ncast2]], %{{.*}} : index
! CHECK-DAG: %[[nselect:.*]] = arith.select %[[ncmpi]], %[[ncast2]], %{{.*}} : index
! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<?x?xf32>, %[[mselect]], %[[nselect]]
! CHECK: %[[shape:.*]] = fir.shape %[[mselect]], %[[nselect]] : (index, index) -> !fir.shape<2>
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_array(%[[m]], %[[n]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?xf32>
! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) : !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>
print *, return_dyn_array(m, n)
end subroutine
! CHECK-LABEL: func @_QMcallerPdyn_char_cst_array(
! CHECK-SAME: %[[l:.*]]: !fir.ref<i32>{{.*}}) {
subroutine dyn_char_cst_array(l)
integer :: l
! CHECK: %[[lload:.*]] = fir.load %[[l]] : !fir.ref<i32>
! CHECK: %[[lcast:.*]] = fir.convert %[[lload]] : (i32) -> i64
! CHECK: %[[lcast2:.*]] = fir.convert %[[lcast]] : (i64) -> index
! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[lcast2]], %{{.*}} : index
! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[lcast2]], %{{.*}} : index
! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<20x30x!fir.char<1,?>>(%[[select]] : index)
! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_cst_array(%[[l]]) {{.*}}: (!fir.ref<i32>) -> !fir.array<20x30x!fir.char<1,?>>
! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) typeparams %[[select]] : !fir.array<20x30x!fir.char<1,?>>, !fir.ref<!fir.array<20x30x!fir.char<1,?>>>, !fir.shape<2>, index
print *, return_dyn_char_cst_array(l)
end subroutine
! CHECK-LABEL: func @_QMcallerPcst_char_dyn_array(
! CHECK-SAME: %[[m:.*]]: !fir.ref<i32>{{.*}}, %[[n:.*]]: !fir.ref<i32>{{.*}}) {
subroutine cst_char_dyn_array(m, n)
integer :: m, n
! CHECK-DAG: %[[mload:.*]] = fir.load %[[m]] : !fir.ref<i32>
! CHECK-DAG: %[[mcast:.*]] = fir.convert %[[mload]] : (i32) -> i64
! CHECK-DAG: %[[msub:.*]] = arith.subi %[[mcast]], %c1{{.*}} : i64
! CHECK-DAG: %[[madd:.*]] = arith.addi %[[msub]], %c1{{.*}} : i64
! CHECK-DAG: %[[mcast2:.*]] = fir.convert %[[madd]] : (i64) -> index
! CHECK-DAG: %[[mcmpi:.*]] = arith.cmpi sgt, %[[mcast2]], %{{.*}} : index
! CHECK-DAG: %[[mselect:.*]] = arith.select %[[mcmpi]], %[[mcast2]], %{{.*}} : index
! CHECK-DAG: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i32>
! CHECK-DAG: %[[ncast:.*]] = fir.convert %[[nload]] : (i32) -> i64
! CHECK-DAG: %[[nsub:.*]] = arith.subi %[[ncast]], %c1{{.*}} : i64
! CHECK-DAG: %[[nadd:.*]] = arith.addi %[[nsub]], %c1{{.*}} : i64
! CHECK-DAG: %[[ncast2:.*]] = fir.convert %[[nadd]] : (i64) -> index
! CHECK-DAG: %[[ncmpi:.*]] = arith.cmpi sgt, %[[ncast2]], %{{.*}} : index
! CHECK-DAG: %[[nselect:.*]] = arith.select %[[ncmpi]], %[[ncast2]], %{{.*}} : index
! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<?x?x!fir.char<1,10>>, %[[mselect]], %[[nselect]]
! CHECK: %[[shape:.*]] = fir.shape %[[mselect]], %[[nselect]] : (index, index) -> !fir.shape<2>
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_dyn_array(%[[m]], %[[n]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,10>>
! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) typeparams {{.*}} : !fir.array<?x?x!fir.char<1,10>>, !fir.ref<!fir.array<?x?x!fir.char<1,10>>>, !fir.shape<2>, index
print *, return_cst_char_dyn_array(m, n)
end subroutine
! CHECK-LABEL: func @_QMcallerPdyn_char_dyn_array(
! CHECK-SAME: %[[l:.*]]: !fir.ref<i32>{{.*}}, %[[m:.*]]: !fir.ref<i32>{{.*}}, %[[n:.*]]: !fir.ref<i32>{{.*}}) {
subroutine dyn_char_dyn_array(l, m, n)
! CHECK-DAG: %[[mload:.*]] = fir.load %[[m]] : !fir.ref<i32>
! CHECK-DAG: %[[mcast:.*]] = fir.convert %[[mload]] : (i32) -> i64
! CHECK-DAG: %[[msub:.*]] = arith.subi %[[mcast]], %c1{{.*}} : i64
! CHECK-DAG: %[[madd:.*]] = arith.addi %[[msub]], %c1{{.*}} : i64
! CHECK-DAG: %[[mcast2:.*]] = fir.convert %[[madd]] : (i64) -> index
! CHECK-DAG: %[[mcmpi:.*]] = arith.cmpi sgt, %[[mcast2]], %{{.*}} : index
! CHECK-DAG: %[[mselect:.*]] = arith.select %[[mcmpi]], %[[mcast2]], %{{.*}} : index
! CHECK-DAG: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i32>
! CHECK-DAG: %[[ncast:.*]] = fir.convert %[[nload]] : (i32) -> i64
! CHECK-DAG: %[[nsub:.*]] = arith.subi %[[ncast]], %c1{{.*}} : i64
! CHECK-DAG: %[[nadd:.*]] = arith.addi %[[nsub]], %c1{{.*}} : i64
! CHECK-DAG: %[[ncast2:.*]] = fir.convert %[[nadd]] : (i64) -> index
! CHECK-DAG: %[[ncmpi:.*]] = arith.cmpi sgt, %[[ncast2]], %{{.*}} : index
! CHECK-DAG: %[[nselect:.*]] = arith.select %[[ncmpi]], %[[ncast2]], %{{.*}} : index
! CHECK-DAG: %[[lload:.*]] = fir.load %[[l]] : !fir.ref<i32>
! CHECK-DAG: %[[lcast:.*]] = fir.convert %[[lload]] : (i32) -> i64
! CHECK-DAG: %[[lcast2:.*]] = fir.convert %[[lcast]] : (i64) -> index
! CHECK-DAG: %[[lcmpi:.*]] = arith.cmpi sgt, %[[lcast2]], %{{.*}} : index
! CHECK-DAG: %[[lselect:.*]] = arith.select %[[lcmpi]], %[[lcast2]], %{{.*}} : index
! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<?x?x!fir.char<1,?>>(%[[lselect]] : index), %[[mselect]], %[[nselect]]
! CHECK: %[[shape:.*]] = fir.shape %[[mselect]], %[[nselect]] : (index, index) -> !fir.shape<2>
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_dyn_array(%[[l]], %[[m]], %[[n]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,?>>
! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) typeparams {{.*}} : !fir.array<?x?x!fir.char<1,?>>, !fir.ref<!fir.array<?x?x!fir.char<1,?>>>, !fir.shape<2>, index
integer :: l, m, n
print *, return_dyn_char_dyn_array(l, m, n)
end subroutine
! CHECK-LABEL: @_QMcallerPdyn_char_alloc
subroutine dyn_char_alloc(l)
integer :: l
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_alloc({{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
print *, return_dyn_char_alloc(l)
! CHECK: _FortranAioOutputDescriptor
! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,?>>>
! CHECK: %[[cmpi:.*]] = arith.cmpi
! CHECK: fir.if %[[cmpi]]
! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,?>>>
end subroutine
! CHECK-LABEL: @_QMcallerPdyn_char_pointer
subroutine dyn_char_pointer(l)
integer :: l
! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_pointer({{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
print *, return_dyn_char_pointer(l)
! CHECK-NOT: fir.freemem
end subroutine
end module
! Test more complex symbol dependencies in the result specification expression
module m_with_equiv
integer(8) :: l
integer(8) :: array(3)
equivalence (array(2), l)
contains
function result_depends_on_equiv_sym()
character(l) :: result_depends_on_equiv_sym
call set_result_with_some_value(result_depends_on_equiv_sym)
end function
end module
! CHECK-LABEL: func @_QPtest_result_depends_on_equiv_sym
subroutine test_result_depends_on_equiv_sym()
use m_with_equiv, only : result_depends_on_equiv_sym
! CHECK: %[[equiv:.*]] = fir.address_of(@_QMm_with_equivEarray) : !fir.ref<!fir.array<24xi8>>
! CHECK: %[[coor:.*]] = fir.coordinate_of %[[equiv]], %c{{.*}} : (!fir.ref<!fir.array<24xi8>>, index) -> !fir.ref<i8>
! CHECK: %[[l:.*]] = fir.convert %[[coor]] : (!fir.ref<i8>) -> !fir.ptr<i64>
! CHECK: %[[load:.*]] = fir.load %[[l]] : !fir.ptr<i64>
! CHECK: %[[lcast:.*]] = fir.convert %[[load]] : (i64) -> index
! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[lcast]], %{{.*}} : index
! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[lcast]], %{{.*}} : index
! CHECK: fir.alloca !fir.char<1,?>(%[[select]] : index)
print *, result_depends_on_equiv_sym()
end subroutine
! CHECK-LABEL: func @_QPtest_depends_on_descriptor(
! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
subroutine test_depends_on_descriptor(x)
interface
function depends_on_descriptor(x)
real :: x(:)
character(size(x,1, KIND=8)) :: depends_on_descriptor
end function
end interface
real :: x(:)
! CHECK: %[[dims:.*]]:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
! CHECK: %[[extentCast:.*]] = fir.convert %[[dims]]#1 : (index) -> i64
! CHECK: %[[extent:.*]] = fir.convert %[[extentCast]] : (i64) -> index
! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[extent]], %{{.*}} : index
! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[extent]], %{{.*}} : index
! CHECK: fir.alloca !fir.char<1,?>(%[[select]] : index)
print *, depends_on_descriptor(x)
end subroutine
! CHECK-LABEL: func @_QPtest_symbol_indirection(
! CHECK-SAME: %[[n:.*]]: !fir.ref<i64>{{.*}}) {
subroutine test_symbol_indirection(n)
interface
function symbol_indirection(c, n)
integer(8) :: n
character(n) :: c
character(len(c, KIND=8)) :: symbol_indirection
end function
end interface
integer(8) :: n
character(n) :: c
! CHECK: BeginExternalListOutput
! CHECK: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i64>
! CHECK: %[[n_is_positive:.*]] = arith.cmpi sgt, %[[nload]], %c0{{.*}} : i64
! CHECK: %[[len:.*]] = arith.select %[[n_is_positive]], %[[nload]], %c0{{.*}} : i64
! CHECK: %[[len_cast:.*]] = fir.convert %[[len]] : (i64) -> index
! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[len_cast]], %{{.*}} : index
! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[len_cast]], %{{.*}} : index
! CHECK: fir.alloca !fir.char<1,?>(%[[select]] : index)
print *, symbol_indirection(c, n)
end subroutine
! CHECK-LABEL: func @_QPtest_recursion(
! CHECK-SAME: %[[res:.*]]: !fir.ref<!fir.char<1,?>>{{.*}}, %[[resLen:.*]]: index{{.*}}, %[[n:.*]]: !fir.ref<i64>{{.*}}) -> !fir.boxchar<1> {
function test_recursion(n) result(res)
integer(8) :: n
character(n) :: res
! some_local is here to verify that local symbols that are visible in the
! function interface are not instantiated by accident (that only the
! symbols needed for the result are instantiated before the call).
! CHECK: fir.alloca !fir.array<?xi32>, {{.*}}some_local
! CHECK-NOT: fir.alloca !fir.array<?xi32>
integer :: some_local(n)
some_local(1) = n + 64
if (n.eq.1) then
res = char(some_local(1))
! CHECK: else
else
! CHECK-NOT: fir.alloca !fir.array<?xi32>
! verify that the actual argument for symbol n ("n-1") is used to allocate
! the result, and not the local value of symbol n.
! CHECK: %[[nLoad:.*]] = fir.load %[[n]] : !fir.ref<i64>
! CHECK: %[[sub:.*]] = arith.subi %[[nLoad]], %c1{{.*}} : i64
! CHECK: fir.store %[[sub]] to %[[nInCall:.*]] : !fir.ref<i64>
! CHECK-NOT: fir.alloca !fir.array<?xi32>
! CHECK: %[[nInCallLoad:.*]] = fir.load %[[nInCall]] : !fir.ref<i64>
! CHECK: %[[nInCallCast:.*]] = fir.convert %[[nInCallLoad]] : (i64) -> index
! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[nInCallCast]], %{{.*}} : index
! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[nInCallCast]], %{{.*}} : index
! CHECK: %[[tmp:.*]] = fir.alloca !fir.char<1,?>(%[[select]] : index)
! CHECK-NOT: fir.alloca !fir.array<?xi32>
! CHECK: fir.call @_QPtest_recursion(%[[tmp]], {{.*}}
res = char(some_local(1)) // test_recursion(n-1)
! Verify that symbol n was not remapped to the actual argument passed
! to n in the call (that the temporary mapping was cleaned-up).
! CHECK: %[[nLoad2:.*]] = fir.load %[[n]] : !fir.ref<i64>
! CHECK: OutputInteger64(%{{.*}}, %[[nLoad2]])
print *, n
end if
end function
! Test call to character function for which only the result type is explicit
! CHECK-LABEL:func @_QPtest_not_entirely_explicit_interface(
! CHECK-SAME: %[[n_arg:.*]]: !fir.ref<i64>{{.*}}) {
subroutine test_not_entirely_explicit_interface(n)
integer(8) :: n
character(n) :: return_dyn_char_2
print *, return_dyn_char_2(10)
! CHECK: %[[n:.*]] = fir.load %[[n_arg]] : !fir.ref<i64>
! CHECK: %[[len:.*]] = fir.convert %[[n]] : (i64) -> index
! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[len]], %{{.*}} : index
! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[len]], %{{.*}} : index
! CHECK: %[[result:.*]] = fir.alloca !fir.char<1,?>(%[[select]] : index) {bindc_name = ".result"}
! CHECK: fir.call @_QPreturn_dyn_char_2(%[[result]], %[[select]], %{{.*}}) {{.*}}: (!fir.ref<!fir.char<1,?>>, index, !fir.ref<i32>) -> !fir.boxchar<1>
end subroutine
|