xref: /llvm-project/flang/test/Lower/assumed-type.f90 (revision d0829fbdeda0a2faa8cf684e1396e579691bdfa2)
1! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
2
3module assumed_type_test
4
5  interface
6    subroutine assumed(a)
7      type(*), intent(in), target :: a
8    end subroutine
9  end interface
10
11  interface
12    subroutine assumed_r(a)
13      type(*), intent(in), target :: a(*)
14    end subroutine
15  end interface
16
17contains
18
19  subroutine call_assumed()
20    integer, target :: i
21    call assumed(i)
22  end subroutine
23
24! CHECK-LABEL: func.func @_QMassumed_type_testPcall_assumed() {
25! CHECK: %[[I:.*]] = fir.alloca i32 {bindc_name = "i", fir.target, uniq_name = "_QMassumed_type_testFcall_assumedEi"}
26! CHECK: %[[CONV:.*]] = fir.convert %[[I]] : (!fir.ref<i32>) -> !fir.ref<none>
27! CHECK: fir.call @_QPassumed(%[[CONV]]) {{.*}}: (!fir.ref<none>) -> ()
28
29  subroutine call_assumed_r()
30    integer, target :: i(10)
31    call assumed_r(i)
32  end subroutine
33
34! CHECK-LABEL: func.func @_QMassumed_type_testPcall_assumed_r() {
35! CHECK: %[[I:.*]] = fir.alloca !fir.array<10xi32> {bindc_name = "i", fir.target, uniq_name = "_QMassumed_type_testFcall_assumed_rEi"}
36! CHECK: %[[CONV:.*]] = fir.convert %[[I]] : (!fir.ref<!fir.array<10xi32>>) -> !fir.ref<!fir.array<?xnone>>
37! CHECK: fir.call @_QPassumed_r(%[[CONV]]) {{.*}} : (!fir.ref<!fir.array<?xnone>>) -> ()
38
39  subroutine assumed_type_optional_to_intrinsic(a)
40    type(*), optional :: a(:)
41    if (present(a)) print*, 'present'
42  end subroutine
43
44! CHECK-LABEL: func.func @_QMassumed_type_testPassumed_type_optional_to_intrinsic(
45! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xnone>> {fir.bindc_name = "a", fir.optional}) {
46! CHECK: %{{.*}} = fir.is_present %[[ARG0]] : (!fir.box<!fir.array<?xnone>>) -> i1
47
48  subroutine assumed_type_lbound(a)
49    type(*), optional :: a(:,:)
50    print*,lbound(a,dim=1)
51  end subroutine
52
53! CHECK-LABEL: func.func @_QMassumed_type_testPassumed_type_lbound(
54! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?x?xnone>> {fir.bindc_name = "a", fir.optional}) {
55! CHECK: %[[C1:.*]] = arith.constant 1 : i32
56! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[C1]]) {{.*}} : (!fir.ref<i8>, i32) -> i1
57
58end module
59