[ConstraintElim] Add support for decomposing gep nuw (#118639)
[llvm-project.git] / flang / test / Lower / call-by-value.f90
blob32b9c79e11e68f0b28e26279b5d212be6fa3df84
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]]) {{.*}}: {{.*}}
13 program call_by_value
14 use iso_c_binding, only: c_bool
15 interface
16 subroutine omp_set_nested(enable) bind(c)
17 import c_bool
18 logical(c_bool), value :: enable
19 end subroutine omp_set_nested
20 end interface
22 logical(c_bool) do_nested
23 do_nested = .FALSE.
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>) -> ()
33 ! CHECK: return
34 ! CHECK: }
36 subroutine test_integer_value(x) bind(c)
37 integer, value :: x
38 call internal_call(x)
39 end
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>) -> ()
46 ! CHECK: return
47 ! CHECK: }
50 subroutine test_real_value(x) bind(c)
51 real, value :: x
52 call internal_call2(x)
53 end
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>>) -> ()
60 ! CHECK: return
61 ! CHECK: }
64 subroutine test_complex_value(x) bind(c)
65 complex, value :: x
66 call internal_call3(x)
67 end
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>) -> ()
77 ! CHECK: return
78 ! CHECK: }
80 subroutine test_char_value(x) bind(c)
81 character(1), value :: x
82 call internal_call4(x)
83 end
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>) -> ()
93 ! CHECK: return
94 ! CHECK: }
95 subroutine test_call_char_value(x)
96 character(*) :: x
97 interface
98 subroutine test_char_value(x) bind(c)
99 character(1), value :: x
101 end interface
102 call test_char_value(x)
103 end subroutine
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}>>) -> ()
114 ! CHECK: return
115 ! CHECK: }
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)