Debian Codegraph @

flang/test/Lower/HLFIR/constant-derived.f90

raw
1 ! Test lowering of Constant<SomeDerived>.
2 ! RUN: bbc -emit-hlfir -o - -I nowhere %s 2>&1 | FileCheck %s
3
4 subroutine test_constant_scalar()
5 type myderived
6 integer :: i
7 integer :: j = 42
8 real :: x(2)
9 character(10) :: c
10 end type
11 print *, myderived(i=1, x=[2.,3.], c="hello")
12 ! CHECK-LABEL: func.func @_QPtest_constant_scalar() {
13 ! CHECK: fir.address_of(@[[CST:_QQro._QFtest_constant_scalarTmyderived..*]])
14 end subroutine
15
16 subroutine test_constant_scalar_ptr_component()
17 type myderived
18 real, pointer :: x
19 real, pointer :: y(:)
20 end type
21 real, target, save :: targ(100)
22 call test(myderived(NULL(), targ(1:50:5)))
23 ! CHECK-LABEL: func.func @_QPtest_constant_scalar_ptr_component() {
24 ! CHECK: fir.address_of(@[[CST_TARGET:_QQro._QFtest_constant_scalar_ptr_componentTmyderived..*]])
25 end subroutine
26
27 subroutine test_comp_ref()
28 ! Test parent component value in an initial value structure constructor.
29 type t1
30 integer :: i
31 end type
32 type, extends(t1) :: t2
33 integer :: j
34 end type
35 type(t2) :: x = t2(t1=t1(1), j=2)
36 end subroutine
37
38 ! CHECK: fir.global internal @[[CST]] constant : !fir.type<[[DERIVED:_QFtest_constant_scalarTmyderived{i:i32,j:i32,x:!fir.array<2xf32>,c:!fir.char<1,10>}]]> {
39 ! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<[[DERIVED]]>
40 ! CHECK: %[[VAL_1:.*]] = fir.field_index i, !fir.type<[[DERIVED]]>
41 ! CHECK: %[[VAL_2:.*]] = arith.constant 1 : i32
42 ! CHECK: %[[VAL_3:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_2]], ["i", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, i32) -> !fir.type<[[DERIVED]]>
43 ! CHECK: %[[VAL_4:.*]] = fir.field_index j, !fir.type<[[DERIVED]]>
44 ! CHECK: %[[VAL_5:.*]] = arith.constant 42 : i32
45 ! CHECK: %[[VAL_6:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_5]], ["j", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, i32) -> !fir.type<[[DERIVED]]>
46 ! CHECK: %[[VAL_7:.*]] = fir.field_index x, !fir.type<[[DERIVED]]>
47 ! CHECK: %[[VAL_8:.*]] = fir.undefined !fir.array<2xf32>
48 ! CHECK: %[[VAL_9:.*]] = arith.constant 2.000000e+00 : f32
49 ! CHECK: %[[VAL_10:.*]] = fir.insert_value %[[VAL_8]], %[[VAL_9]], [0 : index] : (!fir.array<2xf32>, f32) -> !fir.array<2xf32>
50 ! CHECK: %[[VAL_11:.*]] = arith.constant 3.000000e+00 : f32
51 ! CHECK: %[[VAL_12:.*]] = fir.insert_value %[[VAL_10]], %[[VAL_11]], [1 : index] : (!fir.array<2xf32>, f32) -> !fir.array<2xf32>
52 ! CHECK: %[[VAL_13:.*]] = arith.constant 2 : index
53 ! CHECK: %[[VAL_14:.*]] = fir.insert_value %[[VAL_6]], %[[VAL_12]], ["x", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, !fir.array<2xf32>) -> !fir.type<[[DERIVED]]>
54 ! CHECK: %[[VAL_15:.*]] = fir.field_index c, !fir.type<[[DERIVED]]>
55 ! CHECK: %[[VAL_16:.*]] = fir.string_lit "hello "(10) : !fir.char<1,10>
56 ! CHECK: %[[VAL_17:.*]] = arith.constant 10 : index
57 ! CHECK: %[[VAL_18:.*]] = fir.insert_value %[[VAL_14]], %[[VAL_16]], ["c", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, !fir.char<1,10>) -> !fir.type<[[DERIVED]]>
58 ! CHECK: fir.has_value %[[VAL_18]] : !fir.type<[[DERIVED]]>
59 ! CHECK: }
60
61 ! CHECK: fir.global internal @[[CST_TARGET]] constant :
62 ! CHECK-SAME: !fir.type<[[DERIVED_2:_QFtest_constant_scalar_ptr_componentTmyderived{x:!fir.box<!fir.ptr<f32>>,y:!fir.box<!fir.ptr<!fir.array<\?xf32>>>}]]> {
63 ! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<[[DERIVED_2]]>
64 ! CHECK: %[[VAL_1:.*]] = fir.field_index x, !fir.type<[[DERIVED_2]]>
65 ! CHECK: %[[VAL_2:.*]] = fir.zero_bits !fir.ptr<f32>
66 ! CHECK: %[[VAL_3:.*]] = fir.embox %[[VAL_2]] : (!fir.ptr<f32>) -> !fir.box<!fir.ptr<f32>>
67 ! CHECK: %[[VAL_4:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_3]], ["x", !fir.type<[[DERIVED_2]]>] : (!fir.type<[[DERIVED_2]]>, !fir.box<!fir.ptr<f32>>) -> !fir.type<[[DERIVED_2]]>
68 ! CHECK: %[[VAL_5:.*]] = fir.field_index y, !fir.type<[[DERIVED_2]]>
69 ! CHECK: %[[VAL_6:.*]] = fir.address_of(@_QFtest_constant_scalar_ptr_componentEtarg) : !fir.ref<!fir.array<100xf32>>
70 ! CHECK: %[[VAL_7:.*]] = arith.constant 100 : index
71 ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1>
72 ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_8]])
73 ! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index
74 ! CHECK: %[[VAL_13:.*]] = arith.constant 50 : index
75 ! CHECK: %[[VAL_15:.*]] = arith.constant 5 : index
76 ! CHECK: %[[VAL_16:.*]] = arith.constant 10 : index
77 ! CHECK: %[[VAL_17:.*]] = fir.shape %[[VAL_16]] : (index) -> !fir.shape<1>
78 ! CHECK: %[[VAL_18:.*]] = hlfir.designate %[[VAL_9]]#0 (%[[VAL_11]]:%[[VAL_13]]:%[[VAL_15]]) shape %[[VAL_17]] : (!fir.ref<!fir.array<100xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<10xf32>>
79 ! CHECK: %[[VAL_19:.*]] = fir.rebox %[[VAL_18]] : (!fir.box<!fir.array<10xf32>>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
80 ! CHECK: %[[VAL_20:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_19]], ["y", !fir.type<[[DERIVED_2]]>] : (!fir.type<[[DERIVED_2]]>, !fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.type<[[DERIVED_2]]>
81 ! CHECK: fir.has_value %[[VAL_20]] : !fir.type<[[DERIVED_2]]>
82 ! CHECK: }
83
84 ! CHECK-LABEL: fir.global internal @_QFtest_comp_refEx : !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}> {
85 ! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
86 ! CHECK: %[[VAL_1:.*]] = fir.field_index t1, !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
87 ! CHECK: %[[VAL_2:.*]] = fir.undefined !fir.type<_QFtest_comp_refTt1{i:i32}>
88 ! CHECK: %[[VAL_3:.*]] = fir.field_index i, !fir.type<_QFtest_comp_refTt1{i:i32}>
89 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
90 ! CHECK: %[[VAL_5:.*]] = fir.insert_value %[[VAL_2]], %[[VAL_4]], ["i", !fir.type<_QFtest_comp_refTt1{i:i32}>] : (!fir.type<_QFtest_comp_refTt1{i:i32}>, i32) -> !fir.type<_QFtest_comp_refTt1{i:i32}>
91 ! CHECK: %[[VAL_6:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_5]], ["t1", !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>] : (!fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>, !fir.type<_QFtest_comp_refTt1{i:i32}>) -> !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
92 ! CHECK: %[[VAL_7:.*]] = fir.field_index j, !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
93 ! CHECK: %[[VAL_8:.*]] = arith.constant 2 : i32
94 ! CHECK: %[[VAL_9:.*]] = fir.insert_value %[[VAL_6]], %[[VAL_8]], ["j", !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>] : (!fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>, i32) -> !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
95 ! CHECK: fir.has_value %[[VAL_9]] : !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
96 ! CHECK: }