1 ! Test lowering of intrinsic assignments to HLFIR
2 ! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
4 ! -----------------------------------------------------------------------------
5 ! Test assignments with scalar variable LHS and RHS
6 ! -----------------------------------------------------------------------------
8 subroutine scalar_int(x
, y
)
12 ! CHECK-LABEL: func.func @_QPscalar_int(
13 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_intEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
14 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_intEy"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
15 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0
16 ! CHECK: hlfir.assign %[[VAL_4]] to %[[VAL_2]]#0 : i32, !fir.ref<i32>
18 subroutine scalar_logical(x
, y
)
22 ! CHECK-LABEL: func.func @_QPscalar_logical(
23 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_logicalEx"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
24 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_logicalEy"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
25 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0
26 ! CHECK: hlfir.assign %[[VAL_4]] to %[[VAL_2]]#0 : !fir.logical<4>, !fir.ref<!fir.logical<4>>
28 subroutine scalar_real(x
, y
)
32 ! CHECK-LABEL: func.func @_QPscalar_real(
33 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
34 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_realEy"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
35 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0
36 ! CHECK: hlfir.assign %[[VAL_4]] to %[[VAL_2]]#0 : f32, !fir.ref<f32>
38 subroutine scalar_complex(x
, y
)
42 ! CHECK-LABEL: func.func @_QPscalar_complex(
43 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_complexEx"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
44 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_complexEy"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
45 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0
46 ! CHECK: hlfir.assign %[[VAL_4]] to %[[VAL_2]]#0 : !fir.complex<4>, !fir.ref<!fir.complex<4>>
48 subroutine scalar_character(x
, y
)
52 ! CHECK-LABEL: func.func @_QPscalar_character(
53 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_characterEx"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
54 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_characterEy"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
55 ! CHECK: hlfir.assign %[[VAL_5]]#0 to %[[VAL_3]]#0 : !fir.boxchar<1>, !fir.boxchar<1>
57 ! -----------------------------------------------------------------------------
58 ! Test assignments with scalar variable LHS and expression RHS
59 ! -----------------------------------------------------------------------------
61 subroutine scalar_int_2(x
)
65 ! CHECK-LABEL: func.func @_QPscalar_int_2(
66 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_int_2Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
67 ! CHECK: %[[VAL_2:.*]] = arith.constant 42 : i32
68 ! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_1]]#0 : i32, !fir.ref<i32>
70 subroutine scalar_logical_2(x
)
74 ! CHECK-LABEL: func.func @_QPscalar_logical_2(
75 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_logical_2Ex"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
76 ! CHECK: %[[VAL_2:.*]] = arith.constant true
77 ! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_1]]#0 : i1, !fir.ref<!fir.logical<4>>
79 subroutine scalar_real_2(x
)
83 ! CHECK-LABEL: func.func @_QPscalar_real_2(
84 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_real_2Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
85 ! CHECK: %[[VAL_2:.*]] = arith.constant 3.140000e+00 : f32
86 ! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_1]]#0 : f32, !fir.ref<f32>
88 subroutine scalar_complex_2(x
)
92 ! CHECK-LABEL: func.func @_QPscalar_complex_2(
93 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_complex_2Ex"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
94 ! CHECK: %[[VAL_2:.*]] = arith.constant 1.000000e+00 : f32
95 ! CHECK: %[[VAL_3:.*]] = arith.constant -1.000000e+00 : f32
96 ! CHECK: %[[VAL_4:.*]] = fir.undefined !fir.complex<4>
97 ! CHECK: %[[VAL_5:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_2]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
98 ! CHECK: %[[VAL_6:.*]] = fir.insert_value %[[VAL_5]], %[[VAL_3]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
99 ! CHECK: hlfir.assign %[[VAL_6]] to %[[VAL_1]]#0 : !fir.complex<4>, !fir.ref<!fir.complex<4>>
101 subroutine scalar_character_2(x
)
105 ! CHECK-LABEL: func.func @_QPscalar_character_2(
106 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFscalar_character_2Ex"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
107 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}} {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QQcl.68656C6C6F"} : (!fir.ref<!fir.char<1,5>>, index) -> (!fir.ref<!fir.char<1,5>>, !fir.ref<!fir.char<1,5>>)
108 ! CHECK: hlfir.assign %[[VAL_5]]#0 to %[[VAL_2]]#0 : !fir.ref<!fir.char<1,5>>, !fir.boxchar<1>
110 ! -----------------------------------------------------------------------------
111 ! Test assignments with array variable LHS and RHS
112 ! -----------------------------------------------------------------------------
114 subroutine array(x
, y
)
115 integer :: x(:), y(100)
118 ! CHECK-LABEL: func.func @_QParray(
119 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarrayEx"} : (!fir.box<!fir.array<?xi32>>) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
120 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarrayEy"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
121 ! CHECK: hlfir.assign %[[VAL_5]]#0 to %[[VAL_2]]#0 : !fir.ref<!fir.array<100xi32>>, !fir.box<!fir.array<?xi32>>
123 subroutine array_lbs(x
, y
)
124 logical :: x(2:21), y(3:22)
127 ! CHECK-LABEL: func.func @_QParray_lbs(
128 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarray_lbsEx"} : (!fir.ref<!fir.array<20x!fir.logical<4>>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<20x!fir.logical<4>>>, !fir.ref<!fir.array<20x!fir.logical<4>>>)
129 ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarray_lbsEy"} : (!fir.ref<!fir.array<20x!fir.logical<4>>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<20x!fir.logical<4>>>, !fir.ref<!fir.array<20x!fir.logical<4>>>)
130 ! CHECK: hlfir.assign %[[VAL_9]]#0 to %[[VAL_5]]#0 : !fir.box<!fir.array<20x!fir.logical<4>>>, !fir.box<!fir.array<20x!fir.logical<4>>>
133 subroutine array_character(x
, y
)
134 character(*) :: x(10), y(10)
137 ! CHECK-LABEL: func.func @_QParray_character(
138 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarray_characterEx"} : (!fir.ref<!fir.array<10x!fir.char<1,?>>>, !fir.shape<1>, index) -> (!fir.box<!fir.array<10x!fir.char<1,?>>>, !fir.ref<!fir.array<10x!fir.char<1,?>>>)
139 ! CHECK: %[[VAL_11:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarray_characterEy"} : (!fir.ref<!fir.array<10x!fir.char<1,?>>>, !fir.shape<1>, index) -> (!fir.box<!fir.array<10x!fir.char<1,?>>>, !fir.ref<!fir.array<10x!fir.char<1,?>>>)
140 ! CHECK: hlfir.assign %[[VAL_11]]#0 to %[[VAL_6]]#0 : !fir.box<!fir.array<10x!fir.char<1,?>>>, !fir.box<!fir.array<10x!fir.char<1,?>>>
142 subroutine array_pointer(x
, y
)
143 real, pointer :: x(:), y(:)
146 ! CHECK-LABEL: func.func @_QParray_pointer(
147 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %{{.*}}Ex
148 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}}Ey
149 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
150 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
151 ! CHECK: hlfir.assign %[[VAL_3]] to %[[VAL_4]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.box<!fir.ptr<!fir.array<?xf32>>>
153 ! -----------------------------------------------------------------------------
154 ! Test assignments with array LHS and scalar RHS
155 ! -----------------------------------------------------------------------------
157 subroutine array_scalar(x
, y
)
161 ! CHECK-LABEL: func.func @_QParray_scalar(
162 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarray_scalarEx"} : (!fir.ref<!fir.array<100xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>)
163 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFarray_scalarEy"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
164 ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]]#0
165 ! CHECK: hlfir.assign %[[VAL_6]] to %[[VAL_4]]#0 : i32, !fir.ref<!fir.array<100xi32>>
167 ! -----------------------------------------------------------------------------
168 ! Test assignments with whole allocatable LHS
169 ! -----------------------------------------------------------------------------
171 subroutine test_whole_allocatable_assignment(x
, y
)
172 integer, allocatable
:: x(:)
176 ! CHECK-LABEL: func.func @_QPtest_whole_allocatable_assignment(
177 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}Ex"
178 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Ey"
179 ! CHECK: hlfir.assign %[[VAL_3]]#0 to %[[VAL_2]]#0 realloc : !fir.box<!fir.array<?xi32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
181 subroutine test_whole_allocatable_deferred_char(x
, y
)
182 character(:), allocatable
:: x
186 ! CHECK-LABEL: func.func @_QPtest_whole_allocatable_deferred_char(
187 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}Ex"
188 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Ey"
189 ! CHECK: hlfir.assign %[[VAL_4]]#0 to %[[VAL_2]]#0 realloc : !fir.boxchar<1>, !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>
191 subroutine test_whole_allocatable_assumed_char(x
, y
)
192 character(*), allocatable
:: x
196 ! CHECK-LABEL: func.func @_QPtest_whole_allocatable_assumed_char(
197 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Ex"
198 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare {{.*}}Ey"
199 ! CHECK: hlfir.assign %[[VAL_6]]#0 to %[[VAL_4]]#0 realloc keep_lhs_len : !fir.boxchar<1>, !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>