[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / HLFIR / constant.f90
blobfcde5aa3fca6d2802d4f9aeefe571f7c2eef9aa3
1 ! Test lowering of Constant<T>.
2 ! RUN: bbc -hlfir -emit-fir -o - %s 2>&1 | FileCheck %s
4 ! CHECK-LABEL: func.func @_QPtest_constant_scalar()
5 subroutine test_constant_scalar()
6 print *, (10., 20.)
7 ! CHECK-DAG: %[[VAL_0:.*]] = arith.constant 2.000000e+01 : f32
8 ! CHECK-DAG: %[[VAL_1:.*]] = arith.constant 1.000000e+01 : f32
9 ! CHECK: %[[VAL_7:.*]] = fir.undefined !fir.complex<4>
10 ! CHECK: %[[VAL_8:.*]] = fir.insert_value %[[VAL_7]], %[[VAL_1]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
11 ! CHECK: %[[VAL_9:.*]] = fir.insert_value %[[VAL_8]], %[[VAL_0]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
12 end subroutine
14 ! CHECK-LABEL: func.func @_QPtest_constant_scalar_char()
15 subroutine test_constant_scalar_char()
16 print *, "hello"
17 ! CHECK: %[[VAL_5:.*]] = fir.address_of(@[[name:.*]]) : !fir.ref<!fir.char<1,5>>
18 ! CHECK: %[[VAL_6:.*]] = arith.constant 5 : index
19 ! CHECK: hlfir.declare %[[VAL_5]] typeparams %[[VAL_6]] {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "[[name]]"} : (!fir.ref<!fir.char<1,5>>, index) -> (!fir.ref<!fir.char<1,5>>, !fir.ref<!fir.char<1,5>>)
20 end subroutine
22 ! CHECK-LABEL: func.func @_QPtest_constant_array()
23 subroutine test_constant_array()
24 print *, [1., 2., 3.]
25 ! CHECK: %[[VAL_5:.*]] = fir.address_of(@[[name:.*]]) : !fir.ref<!fir.array<3xf32>>
26 ! CHECK: %[[VAL_6:.*]] = arith.constant 3 : index
27 ! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
28 ! CHECK: hlfir.declare %[[VAL_5]](%[[VAL_7]]) {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "[[name]]"} : (!fir.ref<!fir.array<3xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<3xf32>>, !fir.ref<!fir.array<3xf32>>)
29 end subroutine
31 ! CHECK-LABEL: func.func @_QPtest_constant_array_char()
32 subroutine test_constant_array_char()
33 print *, ["abc", "cde"]
34 ! CHECK: %[[VAL_5:.*]] = fir.address_of(@[[name:.*]]) : !fir.ref<!fir.array<2x!fir.char<1,3>>>
35 ! CHECK: %[[VAL_6:.*]] = arith.constant 2 : index
36 ! CHECK: %[[VAL_7:.*]] = arith.constant 3 : index
37 ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
38 ! CHECK: hlfir.declare %[[VAL_5]](%[[VAL_8]]) typeparams %[[VAL_7]] {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "[[name]]"} : (!fir.ref<!fir.array<2x!fir.char<1,3>>>, !fir.shape<1>, index) -> (!fir.ref<!fir.array<2x!fir.char<1,3>>>, !fir.ref<!fir.array<2x!fir.char<1,3>>>)
39 end subroutine
41 ! CHECK-LABEL: func.func @_QPtest_constant_with_lower_bounds()
42 subroutine test_constant_with_lower_bounds()
43 integer, parameter :: i(-1:0, -1:0) = reshape([1,2,3,4], shape=[2,2])
44 print *, i
45 ! CHECK: %[[VAL_12:.*]] = fir.address_of(@_QQro[[name:.*]]) : !fir.ref<!fir.array<2x2xi32>>
46 ! CHECK: %[[VAL_13:.*]] = arith.constant 2 : index
47 ! CHECK: %[[VAL_14:.*]] = arith.constant 2 : index
48 ! CHECK: %[[VAL_15:.*]] = arith.constant -1 : index
49 ! CHECK: %[[VAL_16:.*]] = arith.constant -1 : index
50 ! CHECK: %[[VAL_17:.*]] = fir.shape_shift %[[VAL_15]], %[[VAL_13]], %[[VAL_16]], %[[VAL_14]] : (index, index, index, index) -> !fir.shapeshift<2>
51 ! CHECK: hlfir.declare %[[VAL_12]](%[[VAL_17]]) {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QQro[[name]]"} : (!fir.ref<!fir.array<2x2xi32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<2x2xi32>>, !fir.ref<!fir.array<2x2xi32>>)
52 end subroutine