1 ! Test various aspects around call lowering. More detailed tests around core
2 ! requirements are done in call-xxx.f90 and dummy-argument-xxx.f90 files.
4 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
6 ! CHECK-LABEL: func @_QPtest_nested_calls
7 subroutine test_nested_calls()
12 integer function bar()
15 ! CHECK: %[[result_storage:.*]] = fir.alloca i32 {adapt.valuebyref}
16 ! CHECK: %[[result:.*]] = fir.call @_QPbar() {{.*}}: () -> i32
17 ! CHECK: fir.store %[[result]] to %[[result_storage]] : !fir.ref<i32>
18 ! CHECK: fir.call @_QPfoo(%[[result_storage]]) {{.*}}: (!fir.ref<i32>) -> ()
22 ! Check correct lowering of the result from call to bind(c) function that
24 subroutine call_bindc_char()
26 function int_to_char(int
) bind(c
)
28 character(kind
=c_char
) :: int_to_char
29 integer(c_int
), value
:: int
33 print*, int_to_char(40)
35 ! CHECK-LABEL: func.func @_QPcall_bindc_char
36 ! CHECK: %{{.*}} = fir.call @int_to_char(%{{.*}}) {{.*}}: (i32) -> !fir.char<1>
38 ! Check correct lowering of function body that return char and have the bind(c)
40 function f_int_to_char(i
) bind(c
, name
="f_int_to_char")
42 character(kind
=c_char
) :: f_int_to_char
43 integer(c_int
), value
:: i
44 f_int_to_char
= char(i
)
47 ! CHECK-LABEL: func.func @f_int_to_char(
48 ! CHECK-SAME: %[[ARG0:.*]]: i32 {fir.bindc_name = "i"}) -> !fir.char<1> attributes {fir.bindc_name = "f_int_to_char"} {
49 ! CHECK: %[[CHARBOX:.*]] = fir.alloca !fir.char<1> {adapt.valuebyref}
50 ! CHECK: %[[RESULT:.*]] = fir.alloca !fir.char<1> {bindc_name = "f_int_to_char", uniq_name = "_QFf_int_to_charEf_int_to_char"}
51 ! CHECK: %[[INT_I:.*]] = fir.alloca i32
52 ! CHECK: fir.store %[[ARG0]] to %[[INT_I]] : !fir.ref<i32>
53 ! CHECK: %[[ARG0_2:.*]] = fir.load %[[INT_I]] : !fir.ref<i32>
54 ! CHECK: %[[ARG0_I64:.*]] = fir.convert %[[ARG0_2]] : (i32) -> i64
55 ! CHECK: %[[ARG0_I8:.*]] = fir.convert %[[ARG0_I64]] : (i64) -> i8
56 ! CHECK: %[[UNDEF:.*]] = fir.undefined !fir.char<1>
57 ! CHECK: %[[CHAR_RES:.*]] = fir.insert_value %[[UNDEF]], %[[ARG0_I8]], [0 : index] : (!fir.char<1>, i8) -> !fir.char<1>
58 ! CHECK: fir.store %[[CHAR_RES]] to %[[CHARBOX]] : !fir.ref<!fir.char<1>>
59 ! CHECK: %[[LOAD_CHARBOX:.*]] = fir.load %[[CHARBOX]] : !fir.ref<!fir.char<1>>
60 ! CHECK: fir.store %[[LOAD_CHARBOX]] to %[[RESULT]] : !fir.ref<!fir.char<1>>
61 ! CHECK: %[[LOAD_RES:.*]] = fir.load %[[RESULT]] : !fir.ref<!fir.char<1>>
62 ! CHECK: return %[[LOAD_RES]] : !fir.char<1>