[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / HLFIR / convert-variable.f90
blobab9425afe3f1ed7170aa663fe4f323884b5f5aa4
1 ! Test lowering of variables to fir.declare
2 ! RUN: bbc -emit-fir -hlfir %s -o - | FileCheck %s
4 subroutine scalar_numeric(x)
5 integer :: x
6 end subroutine
7 ! CHECK-LABEL: func.func @_QPscalar_numeric(
8 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>
9 ! CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {uniq_name = "_QFscalar_numericEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
11 subroutine scalar_character(c)
12 character(*) :: c
13 end subroutine
14 ! CHECK-LABEL: func.func @_QPscalar_character(
15 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>
16 ! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
17 ! CHECK: %[[VAL_2:.*]] = hlfir.declare %[[VAL_1]]#0 typeparams %[[VAL_1]]#1 {uniq_name = "_QFscalar_characterEc"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
19 subroutine scalar_character_cst_len(c)
20 character(10) :: c
21 end subroutine
22 ! CHECK-LABEL: func.func @_QPscalar_character_cst_len(
23 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>
24 ! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
25 ! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index
26 ! CHECK: %[[VAL_3:.*]] = hlfir.declare %[[VAL_1]]#0 typeparams %[[VAL_2]] {uniq_name = "_QFscalar_character_cst_lenEc"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
28 subroutine array_numeric(x)
29 integer :: x(10, 20)
30 end subroutine
31 ! CHECK-LABEL: func.func @_QParray_numeric(
32 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10x20xi32>>
33 ! CHECK: %[[VAL_1:.*]] = arith.constant 10 : index
34 ! CHECK: %[[VAL_2:.*]] = arith.constant 20 : index
35 ! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shape<2>
36 ! CHECK: %[[VAL_4:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "_QFarray_numericEx"} : (!fir.ref<!fir.array<10x20xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<10x20xi32>>, !fir.ref<!fir.array<10x20xi32>>)
39 subroutine array_numeric_lbounds(x)
40 integer :: x(-1:10, -2:20)
41 end subroutine
42 ! CHECK-LABEL: func.func @_QParray_numeric_lbounds(
43 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<12x23xi32>>
44 ! CHECK: %[[VAL_1:.*]] = arith.constant -1 : index
45 ! CHECK: %[[VAL_2:.*]] = arith.constant 12 : index
46 ! CHECK: %[[VAL_3:.*]] = arith.constant -2 : index
47 ! CHECK: %[[VAL_4:.*]] = arith.constant 23 : index
48 ! CHECK: %[[VAL_5:.*]] = fir.shape_shift %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (index, index, index, index) -> !fir.shapeshift<2>
49 ! CHECK: %[[VAL_6:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_5]]) {uniq_name = "_QFarray_numeric_lboundsEx"} : (!fir.ref<!fir.array<12x23xi32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<12x23xi32>>, !fir.ref<!fir.array<12x23xi32>>)
51 subroutine array_character(c)
52 character(*) :: c(50)
53 end subroutine
54 ! CHECK-LABEL: func.func @_QParray_character(
55 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>
56 ! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
57 ! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<50x!fir.char<1,?>>>
58 ! CHECK: %[[VAL_3:.*]] = arith.constant 50 : index
59 ! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
60 ! CHECK: %[[VAL_5:.*]] = hlfir.declare %[[VAL_2]](%[[VAL_4]]) typeparams %[[VAL_1]]#1 {uniq_name = "_QFarray_characterEc"} : (!fir.ref<!fir.array<50x!fir.char<1,?>>>, !fir.shape<1>, index) -> (!fir.box<!fir.array<50x!fir.char<1,?>>>, !fir.ref<!fir.array<50x!fir.char<1,?>>>)
62 subroutine scalar_numeric_attributes(x)
63 integer, optional, target, intent(in) :: x
64 end subroutine
65 ! CHECK-LABEL: func.func @_QPscalar_numeric_attributes(
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>
67 ! CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<intent_in, optional, target>, uniq_name = "_QFscalar_numeric_attributesEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
69 subroutine scalar_numeric_attributes_2(x)
70 real(16), value :: x(100)
71 end subroutine
72 ! CHECK-LABEL: func.func @_QPscalar_numeric_attributes_2(
73 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<100xf128>>
74 ! CHECK: %[[VAL_1:.*]] = arith.constant 100 : index
75 ! CHECK: %[[VAL_2:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
76 ! CHECK: %[[VAL_3:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_2]]) {fortran_attrs = #fir.var_attrs<value>, uniq_name = "_QFscalar_numeric_attributes_2Ex"} : (!fir.ref<!fir.array<100xf128>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf128>>, !fir.ref<!fir.array<100xf128>>)
78 subroutine scalar_numeric_attributes_3(x)
79 real, intent(in) :: x
80 end subroutine
81 ! CHECK-LABEL: func.func @_QPscalar_numeric_attributes_3(
82 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32>
83 ! CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFscalar_numeric_attributes_3Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
85 subroutine scalar_numeric_attributes_4(x)
86 logical(8), intent(out) :: x
87 end subroutine
88 ! CHECK-LABEL: func.func @_QPscalar_numeric_attributes_4(
89 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.logical<8>>
90 ! CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<intent_out>, uniq_name = "_QFscalar_numeric_attributes_4Ex"} : (!fir.ref<!fir.logical<8>>) -> (!fir.ref<!fir.logical<8>>, !fir.ref<!fir.logical<8>>)
92 subroutine scalar_numeric_parameter()
93 integer, parameter :: p = 42
94 end subroutine
95 ! CHECK-LABEL: func.func @_QPscalar_numeric_parameter() {
96 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QFscalar_numeric_parameterECp) : !fir.ref<i32>
97 ! CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QFscalar_numeric_parameterECp"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)