1 ! Test for PassBy::Value
2 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
4 !CHECK-LABEL: func @_QQmain()
5 !CHECK: %[[LOGICAL:.*]] = fir.alloca !fir.logical<1>
6 !CHECK: %false = arith.constant false
7 !CHECK: %[[VALUE:.*]] = fir.convert %false : (i1) -> !fir.logical<1>
8 !CHECK: fir.store %[[VALUE]] to %[[LOGICAL]]
9 !CHECK: %[[LOAD:.*]] = fir.load %[[LOGICAL]]
10 !CHECK: fir.call @omp_set_nested(%[[LOAD]]) {{.*}}: {{.*}}
13 use iso_c_binding
, only
: c_bool
15 subroutine omp_set_nested(enable
) bind(c
)
17 logical(c_bool
), value
:: enable
18 end subroutine omp_set_nested
21 logical(c_bool
) do_nested
23 call omp_set_nested(do_nested
)
24 end program call_by_value
26 ! CHECK-LABEL: func.func @test_integer_value(
27 ! CHECK-SAME: %[[VAL_0:.*]]: i32 {fir.bindc_name = "x"}) attributes {fir.bindc_name = "test_integer_value"} {
28 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32
29 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<i32>
30 ! CHECK: fir.call @_QPinternal_call(%[[VAL_1]]) {{.*}}: (!fir.ref<i32>) -> ()
34 subroutine test_integer_value(x
) bind(c
)
39 ! CHECK-LABEL: func.func @test_real_value(
40 ! CHECK-SAME: %[[VAL_0:.*]]: f32 {fir.bindc_name = "x"}) attributes {fir.bindc_name = "test_real_value"} {
41 ! CHECK: %[[VAL_1:.*]] = fir.alloca f32
42 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<f32>
43 ! CHECK: fir.call @_QPinternal_call2(%[[VAL_1]]) {{.*}}: (!fir.ref<f32>) -> ()
47 subroutine test_real_value(x
) bind(c
)
49 call internal_call2(x
)
52 ! CHECK-LABEL: func.func @test_complex_value(
53 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.complex<4> {fir.bindc_name = "x"}) attributes {fir.bindc_name = "test_complex_value"} {
54 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.complex<4>
55 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<!fir.complex<4>>
56 ! CHECK: fir.call @_QPinternal_call3(%[[VAL_1]]) {{.*}}: (!fir.ref<!fir.complex<4>>) -> ()
60 subroutine test_complex_value(x
) bind(c
)
62 call internal_call3(x
)
65 ! CHECK-LABEL: func.func @test_char_value(
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1> {fir.bindc_name = "x"}) attributes {fir.bindc_name = "test_char_value"} {
67 ! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
68 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1>>
69 ! CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
70 ! CHECK: %[[VAL_5:.*]] = fir.emboxchar %[[VAL_3]], %[[VAL_2]] : (!fir.ref<!fir.char<1>>, index) -> !fir.boxchar<1>
71 ! CHECK: fir.call @_QPinternal_call4(%[[VAL_5]]) fastmath<contract> : (!fir.boxchar<1>) -> ()
75 subroutine test_char_value(x
) bind(c
)
76 character(1), value
:: x
77 call internal_call4(x
)
80 ! CHECK-LABEL: func.func @_QPtest_cptr_value(
81 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "x"}) {
82 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
83 ! CHECK: %[[VAL_2:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
84 ! CHECK: %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.field) -> !fir.ref<i64>
85 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<i64>) -> i64
86 ! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<i64>
87 ! CHECK: fir.call @_QPinternal_call5(%[[VAL_1]]) {{.*}}: (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> ()
91 subroutine test_cptr_value(x
)
93 type(c_ptr
), value
:: x
94 call internal_call5(x
)