1 ! Test for PassBy::Value
2 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
4 !CHECK-LABEL: func @_QQmain()
5 !CHECK: %false = arith.constant false
6 !CHECK: %[[LOGICAL_ALLOC:.*]] = fir.alloca !fir.logical<1>
7 !CHECK: %[[LOGICAL:.*]] = fir.declare %[[LOGICAL_ALLOC]]
8 !CHECK: %[[VALUE:.*]] = fir.convert %false : (i1) -> !fir.logical<1>
9 !CHECK: fir.store %[[VALUE]] to %[[LOGICAL]]
10 !CHECK: %[[LOAD:.*]] = fir.load %[[LOGICAL]]
11 !CHECK: fir.call @omp_set_nested(%[[LOAD]]) {{.*}}: {{.*}}
14 use iso_c_binding
, only
: c_bool
16 subroutine omp_set_nested(enable
) bind(c
)
18 logical(c_bool
), value
:: enable
19 end subroutine omp_set_nested
22 logical(c_bool
) do_nested
24 call omp_set_nested(do_nested
)
25 end program call_by_value
27 ! CHECK-LABEL: func.func @test_integer_value(
28 ! CHECK-SAME: %[[VAL_0:.*]]: i32
29 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32
30 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<i32>
31 ! CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_1]]
32 ! CHECK: fir.call @_QPinternal_call(%[[VAL_2]]) {{.*}}: (!fir.ref<i32>) -> ()
36 subroutine test_integer_value(x
) bind(c
)
40 ! CHECK-LABEL: func.func @test_real_value(
41 ! CHECK-SAME: %[[VAL_0:.*]]: f32
42 ! CHECK: %[[VAL_1:.*]] = fir.alloca f32
43 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<f32>
44 ! CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_1]]
45 ! CHECK: fir.call @_QPinternal_call2(%[[VAL_2]]) {{.*}}: (!fir.ref<f32>) -> ()
50 subroutine test_real_value(x
) bind(c
)
52 call internal_call2(x
)
54 ! CHECK-LABEL: func.func @test_complex_value(
55 ! CHECK-SAME: %[[VAL_0:.*]]: complex<f32>
56 ! CHECK: %[[VAL_1:.*]] = fir.alloca complex<f32>
57 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<complex<f32>>
58 ! CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_1]]
59 ! CHECK: fir.call @_QPinternal_call3(%[[VAL_2]]) {{.*}}: (!fir.ref<complex<f32>>) -> ()
64 subroutine test_complex_value(x
) bind(c
)
66 call internal_call3(x
)
69 ! CHECK-LABEL: func.func @test_char_value(
70 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.char<1>
71 ! CHECK: %[[VAL_1:.*]] = arith.constant 1 : index
72 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.char<1>
73 ! CHECK: fir.store %[[VAL_0]] to %[[VAL_2]] : !fir.ref<!fir.char<1>>
74 ! CHECK: %[[VAL_3:.*]] = fir.declare %[[VAL_2]] typeparams %[[VAL_1]]
75 ! CHECK: %[[VAL_4:.*]] = fir.emboxchar %[[VAL_3]], %[[VAL_1]] : (!fir.ref<!fir.char<1>>, index) -> !fir.boxchar<1>
76 ! CHECK: fir.call @_QPinternal_call4(%[[VAL_4]]) {{.*}}: (!fir.boxchar<1>) -> ()
80 subroutine test_char_value(x
) bind(c
)
81 character(1), value
:: x
82 call internal_call4(x
)
85 ! CHECK-LABEL: func.func @_QPtest_call_char_value(
86 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>
87 ! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
88 ! CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_1]]#0 typeparams %[[VAL_1]]#1
89 ! CHECK: %[[VAL_3:.*]] = fir.emboxchar %[[VAL_2]], %[[VAL_1]]#1 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
90 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1>>
91 ! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.char<1>>
92 ! CHECK: fir.call @test_char_value(%[[VAL_5]]) {{.*}}: (!fir.char<1>) -> ()
95 subroutine test_call_char_value(x
)
98 subroutine test_char_value(x
) bind(c
)
99 character(1), value
:: x
102 call test_char_value(x
)
105 ! CHECK-LABEL: func.func @_QPtest_cptr_value(
106 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64>
107 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
108 ! CHECK: %[[VAL_2:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
109 ! 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>
110 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<i64>) -> i64
111 ! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<i64>
112 ! CHECK: %[[VAL_5:.*]] = fir.declare %[[VAL_1]]
113 ! CHECK: fir.call @_QPinternal_call5(%[[VAL_5]]) fastmath<contract> : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> ()
117 subroutine test_cptr_value(x
)
118 use iso_c_binding
, only
: c_ptr
119 type(c_ptr
), value
:: x
120 call internal_call5(x
)