Files
TheRock/compiler/amd-llvm/flang/test/Lower/allocatable-callee.f90
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

184 lines
9.8 KiB
Fortran

! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
! Test allocatable dummy argument on callee side
! CHECK-LABEL: func @_QPtest_scalar(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<f32>>>{{.*}})
subroutine test_scalar(x)
real, allocatable :: x
print *, x
! CHECK: %[[x:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[x]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>
! CHECK: %[[val:.*]] = fir.load %[[addr]] : !fir.heap<f32>
end subroutine
! CHECK-LABEL: func @_QPtest_array(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>{{.*}})
subroutine test_array(x)
integer, allocatable :: x(:,:)
print *, x(1,2)
! CHECK: %[[x:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[x]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
! CHECK: %[[elem:.*]] = hlfir.designate %[[box]] (%{{.*}}, %{{.*}}) : (!fir.box<!fir.heap<!fir.array<?x?xi32>>>, index, index) -> !fir.ref<i32>
! CHECK: fir.load %[[elem]] : !fir.ref<i32>
end subroutine
! CHECK-LABEL: func @_QPtest_char_scalar_deferred(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>{{.*}})
subroutine test_char_scalar_deferred(c)
character(:), allocatable :: c
external foo1
call foo1(c)
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
! CHECK-DAG: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> !fir.heap<!fir.char<1,?>>
! CHECK-DAG: %[[box1:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
! CHECK-DAG: %[[len:.*]] = fir.box_elesize %[[box1]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> index
! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[addr]], %[[len]] : (!fir.heap<!fir.char<1,?>>, index) -> !fir.boxchar<1>
! CHECK: fir.call @_QPfoo1(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
end subroutine
! CHECK-LABEL: func @_QPtest_char_scalar_explicit_cst(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.char<1,10>>>>{{.*}})
subroutine test_char_scalar_explicit_cst(c)
character(10), allocatable :: c
external foo1
call foo1(c)
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,10>>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<!fir.char<1,10>>>) -> !fir.heap<!fir.char<1,10>>
! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.char<1,10>>) -> !fir.ref<!fir.char<1,10>>
! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[cast]], %c10{{.*}} : (!fir.ref<!fir.char<1,10>>, index) -> !fir.boxchar<1>
! CHECK: fir.call @_QPfoo1(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
end subroutine
! CHECK-LABEL: func @_QPtest_char_scalar_explicit_dynamic(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>{{.*}}, %[[arg1:.*]]: !fir.ref<i32>{{.*}})
subroutine test_char_scalar_explicit_dynamic(c, n)
integer :: n
character(n), allocatable :: c
external foo1
! Check that the length expr was evaluated before the execution parts.
! CHECK: %[[n:.*]]:2 = hlfir.declare %[[arg1]]
! CHECK: %[[raw_len:.*]] = fir.load %[[n]]#0 : !fir.ref<i32>
! CHECK: %[[c0_i32:.*]] = arith.constant 0 : i32
! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[raw_len]], %[[c0_i32]] : i32
! CHECK: %[[len:.*]] = arith.select %[[cmp]], %[[raw_len]], %[[c0_i32]] : i32
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]] typeparams %[[len]]{{.*}}allocatable
n = n + 1
! CHECK: hlfir.assign %{{.*}} to %[[n]]#0 : i32, !fir.ref<i32>
call foo1(c)
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
! CHECK: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> !fir.heap<!fir.char<1,?>>
! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[addr]], %[[len]] : (!fir.heap<!fir.char<1,?>>, i32) -> !fir.boxchar<1>
! CHECK: fir.call @_QPfoo1(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
end subroutine
! CHECK-LABEL: func @_QPtest_char_array_deferred(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>{{.*}})
subroutine test_char_array_deferred(c)
character(:), allocatable :: c(:)
external foo1
call foo1(c(10))
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
! CHECK: %[[len:.*]] = fir.box_elesize %[[box]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> index
! CHECK: %[[boxchar:.*]] = hlfir.designate %[[box]] (%{{.*}}) typeparams %[[len]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, index, index) -> !fir.boxchar<1>
! CHECK: fir.call @_QPfoo1(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
end subroutine
! CHECK-LABEL: func @_QPtest_char_array_explicit_cst(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>{{.*}})
subroutine test_char_array_explicit_cst(c)
character(10), allocatable :: c(:)
external foo1
call foo1(c(3))
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
! CHECK: %[[elem:.*]] = hlfir.designate %[[box]] (%{{.*}}) typeparams %c10{{.*}} : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, index, index) -> !fir.ref<!fir.char<1,10>>
! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[elem]], %c10{{.*}} : (!fir.ref<!fir.char<1,10>>, index) -> !fir.boxchar<1>
! CHECK: fir.call @_QPfoo1(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
end subroutine
! CHECK-LABEL: func @_QPtest_char_array_explicit_dynamic(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>{{.*}}, %[[arg1:.*]]: !fir.ref<i32>{{.*}})
subroutine test_char_array_explicit_dynamic(c, n)
integer :: n
character(n), allocatable :: c(:)
external foo1
! Check that the length expr was evaluated before the execution parts.
! CHECK: %[[n:.*]]:2 = hlfir.declare %[[arg1]]
! CHECK: %[[raw_len:.*]] = fir.load %[[n]]#0 : !fir.ref<i32>
! CHECK: %[[c0_i32:.*]] = arith.constant 0 : i32
! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[raw_len]], %[[c0_i32]] : i32
! CHECK: %[[len:.*]] = arith.select %[[cmp]], %[[raw_len]], %[[c0_i32]] : i32
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]] typeparams %[[len]]{{.*}}allocatable
n = n + 1
! CHECK: hlfir.assign %{{.*}} to %[[n]]#0 : i32, !fir.ref<i32>
call foo1(c(1))
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
! CHECK: %[[boxchar:.*]] = hlfir.designate %[[box]] (%{{.*}}) typeparams %[[len]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, index, i32) -> !fir.boxchar<1>
! CHECK: fir.call @_QPfoo1(%[[boxchar]]) {{.*}}: (!fir.boxchar<1>) -> ()
end subroutine
! Check that when reading allocatable length from descriptor, the width is taking
! into account when the kind is not 1.
! CHECK-LABEL: func @_QPtest_char_scalar_deferred_k2(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.char<2,?>>>>{{.*}})
subroutine test_char_scalar_deferred_k2(c)
character(kind=2, len=:), allocatable :: c
external foo2
call foo2(c)
! CHECK: %[[c:.*]]:2 = hlfir.declare %[[arg0]]{{.*}}allocatable
! CHECK: %[[box:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<2,?>>>>
! CHECK-DAG: %[[addr:.*]] = fir.box_addr %[[box]] : (!fir.box<!fir.heap<!fir.char<2,?>>>) -> !fir.heap<!fir.char<2,?>>
! CHECK-DAG: %[[box1:.*]] = fir.load %[[c]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<2,?>>>>
! CHECK-DAG: %[[size:.*]] = fir.box_elesize %[[box1]] : (!fir.box<!fir.heap<!fir.char<2,?>>>) -> index
! CHECK-DAG: %[[len:.*]] = arith.divsi %[[size]], %c2{{.*}} : index
! CHECK: %[[boxchar:.*]] = fir.emboxchar %[[addr]], %[[len]] : (!fir.heap<!fir.char<2,?>>, index) -> !fir.boxchar<2>
! CHECK: fir.call @_QPfoo2(%[[boxchar]]) {{.*}}: (!fir.boxchar<2>) -> ()
end subroutine
! Check that assumed length character allocatables are reading the length from
! the descriptor.
! CHECK-LABEL: _QPtest_char_assumed(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>{{.*}}
subroutine test_char_assumed(a)
integer :: n
character(len=*), allocatable :: a
! CHECK: %[[argLoad:.*]] = fir.load %[[arg0]] : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
! CHECK: %[[argLen:.*]] = fir.box_elesize %[[argLoad]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> index
! CHECK: hlfir.declare %[[arg0]] typeparams %[[argLen]]{{.*}}allocatable
n = len(a)
! CHECK: %[[argLenCast:.*]] = fir.convert %[[argLen]] : (index) -> i32
! CHECK: hlfir.assign %[[argLenCast]] to %{{.*}} : i32, !fir.ref<i32>
end subroutine
! CHECK-LABEL: _QPtest_char_assumed_optional(
! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>{{.*}}
subroutine test_char_assumed_optional(a)
integer :: n
character(len=*), allocatable, optional :: a
! CHECK: %[[argPresent:.*]] = fir.is_present %[[arg0]] : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) -> i1
! CHECK: %[[argLen:.*]] = fir.if %[[argPresent]] -> (index) {
! CHECK: %[[argLoad:.*]] = fir.load %[[arg0]] : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
! CHECK: %[[argEleSz:.*]] = fir.box_elesize %[[argLoad]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> index
! CHECK: fir.result %[[argEleSz]] : index
! CHECK: } else {
! CHECK: %[[undef:.*]] = fir.undefined index
! CHECK: fir.result %[[undef]] : index
! CHECK: %[[a:.*]]:2 = hlfir.declare %[[arg0]] typeparams %[[argLen]]{{.*}}allocatable, optional
if (present(a)) then
n = len(a)
! CHECK: %[[argLenCast:.*]] = fir.convert %[[argLen]] : (index) -> i32
! CHECK: hlfir.assign %[[argLenCast]] to %{{.*}} : i32, !fir.ref<i32>
endif
end subroutine