Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / pointer-args-callee.f90
blob531f6b696947219fe5e7236c715b41b8cd29a7bf
1 ! Test calls with POINTER dummy arguments on the callee side.
2 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
4 ! CHECK-LABEL: func @_QPchar_assumed(
5 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.char<1,?>>>>{{.*}}
6 subroutine char_assumed(a)
7 integer :: n
8 character(len=*), pointer :: a
9 ! CHECK: %[[argLoad:.*]] = fir.load %[[arg0]] : !fir.ref<!fir.box<!fir.ptr<!fir.char<1,?>>>>
10 ! CHECK: %[[argLen:.*]] = fir.box_elesize %[[argLoad]] : (!fir.box<!fir.ptr<!fir.char<1,?>>>) -> index
12 n = len(a)
13 ! CHECK: %[[argLenCast:.*]] = fir.convert %[[argLen]] : (index) -> i32
14 ! CHECK: fir.store %[[argLenCast]] to %{{.*}} : !fir.ref<i32>
15 end subroutine
17 ! CHECK-LABEL: func @_QPchar_assumed_optional(
18 ! CHECK-SAME: %[[arg0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.char<1,?>>>>{{.*}}
19 subroutine char_assumed_optional(a)
20 integer :: n
21 character(len=*), pointer, optional :: a
22 ! CHECK: %[[argPresent:.*]] = fir.is_present %[[arg0]] : (!fir.ref<!fir.box<!fir.ptr<!fir.char<1,?>>>>) -> i1
23 ! CHECK: %[[argLen:.*]] = fir.if %[[argPresent]] -> (index) {
24 ! CHECK: %[[argLoad:.*]] = fir.load %[[arg0]] : !fir.ref<!fir.box<!fir.ptr<!fir.char<1,?>>>>
25 ! CHECK: %[[argLoadLen:.*]] = fir.box_elesize %[[argLoad]] : (!fir.box<!fir.ptr<!fir.char<1,?>>>) -> index
26 ! CHECK: fir.result %[[argLoadLen]] : index
27 ! CHECK: } else {
28 ! CHECK: %[[undef:.*]] = fir.undefined index
29 ! CHECK: fir.result %[[undef]] : index
30 ! CHECK: }
32 if (present(a)) then
33 n = len(a)
34 ! CHECK: %[[argLenCast:.*]] = fir.convert %[[argLen]] : (index) -> i32
35 ! CHECK: fir.store %[[argLenCast]] to %{{.*}} : !fir.ref<i32>
36 endif
37 end subroutine