[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / HLFIR / function-return.f90
blobdbabb0597ab64fb3c52323484b4f226b73606b7b
1 ! Test lowering of function return to HLFIR
2 ! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
4 integer function simple_return()
5 simple_return = 42
6 end function
7 ! CHECK-LABEL: func.func @_QPsimple_return() -> i32 {
8 ! CHECK: %[[VAL_0:.*]] = fir.alloca i32
9 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFsimple_returnEsimple_return"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
10 ! CHECK: %[[VAL_2:.*]] = arith.constant 42 : i32
11 ! CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_1]]#0 : i32, !fir.ref<i32>
12 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_1]]#1 : !fir.ref<i32>
13 ! CHECK: return %[[VAL_3]] : i32
15 character(10) function char_return()
16 char_return = "hello"
17 end function
18 ! CHECK-LABEL: func.func @_QPchar_return(
19 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.char<1,10>>
20 ! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.char<1,10>>) -> !fir.ref<!fir.char<1,?>>
21 ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index
22 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_2]] typeparams %[[VAL_3]] {uniq_name = "_QFchar_returnEchar_return"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
23 ! CHECK: %[[VAL_8:.*]] = fir.emboxchar %[[VAL_4]]#1, %[[VAL_3]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
24 ! CHECK: return %[[VAL_8]] : !fir.boxchar<1>
26 integer function array_return()
27 dimension :: array_return(10)
28 array_return = 42
29 end function
30 ! CHECK-LABEL: func.func @_QParray_return() -> !fir.array<10xi32> {
31 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<10xi32>
32 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]]{{.*}} {uniq_name = "_QFarray_returnEarray_return"} : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>)
33 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#1 : !fir.ref<!fir.array<10xi32>>
34 ! CHECK: return %[[VAL_4]] : !fir.array<10xi32>
36 character(5) function char_array_return()
37 dimension :: char_array_return(10)
38 char_array_return = "hello"
39 end function
40 ! CHECK-LABEL: func.func @_QPchar_array_return() -> !fir.array<10x!fir.char<1,5>> {
41 ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.array<10x!fir.char<1,5>>
42 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_2]]{{.*}} {uniq_name = "_QFchar_array_returnEchar_array_return"} : (!fir.ref<!fir.array<10x!fir.char<1,5>>>, !fir.shape<1>, index) -> (!fir.ref<!fir.array<10x!fir.char<1,5>>>, !fir.ref<!fir.array<10x!fir.char<1,5>>>)
43 ! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]]#1 : !fir.ref<!fir.array<10x!fir.char<1,5>>>
44 ! CHECK: return %[[VAL_5]] : !fir.array<10x!fir.char<1,5>>