1 ! Test lowering of Constant<SomeDerived>.
2 ! RUN: bbc -hlfir -emit-fir -o - -I nowhere %s 2>&1 | FileCheck %s
4 subroutine test_constant_scalar()
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..*]])
16 subroutine test_constant_scalar_ptr_component()
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..*]])
27 ! 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>}]]> {
28 ! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<[[DERIVED]]>
29 ! CHECK: %[[VAL_1:.*]] = fir.field_index i, !fir.type<[[DERIVED]]>
30 ! CHECK: %[[VAL_2:.*]] = arith.constant 1 : i32
31 ! CHECK: %[[VAL_3:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_2]], ["i", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, i32) -> !fir.type<[[DERIVED]]>
32 ! CHECK: %[[VAL_4:.*]] = fir.field_index j, !fir.type<[[DERIVED]]>
33 ! CHECK: %[[VAL_5:.*]] = arith.constant 42 : i32
34 ! CHECK: %[[VAL_6:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_5]], ["j", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, i32) -> !fir.type<[[DERIVED]]>
35 ! CHECK: %[[VAL_7:.*]] = fir.field_index x, !fir.type<[[DERIVED]]>
36 ! CHECK: %[[VAL_8:.*]] = fir.undefined !fir.array<2xf32>
37 ! CHECK: %[[VAL_9:.*]] = arith.constant 2.000000e+00 : f32
38 ! CHECK: %[[VAL_10:.*]] = fir.insert_value %[[VAL_8]], %[[VAL_9]], [0 : index] : (!fir.array<2xf32>, f32) -> !fir.array<2xf32>
39 ! CHECK: %[[VAL_11:.*]] = arith.constant 3.000000e+00 : f32
40 ! CHECK: %[[VAL_12:.*]] = fir.insert_value %[[VAL_10]], %[[VAL_11]], [1 : index] : (!fir.array<2xf32>, f32) -> !fir.array<2xf32>
41 ! CHECK: %[[VAL_13:.*]] = arith.constant 2 : index
42 ! CHECK: %[[VAL_14:.*]] = fir.insert_value %[[VAL_6]], %[[VAL_12]], ["x", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, !fir.array<2xf32>) -> !fir.type<[[DERIVED]]>
43 ! CHECK: %[[VAL_15:.*]] = fir.field_index c, !fir.type<[[DERIVED]]>
44 ! CHECK: %[[VAL_16:.*]] = fir.string_lit "hello "(10) : !fir.char<1,10>
45 ! CHECK: %[[VAL_17:.*]] = arith.constant 10 : index
46 ! CHECK: %[[VAL_18:.*]] = fir.insert_value %[[VAL_14]], %[[VAL_16]], ["c", !fir.type<[[DERIVED]]>] : (!fir.type<[[DERIVED]]>, !fir.char<1,10>) -> !fir.type<[[DERIVED]]>
47 ! CHECK: fir.has_value %[[VAL_18]] : !fir.type<[[DERIVED]]>
50 ! CHECK: fir.global internal @[[CST_TARGET]] constant :
51 ! 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>>>}]]> {
52 ! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<[[DERIVED_2]]>
53 ! CHECK: %[[VAL_1:.*]] = fir.field_index x, !fir.type<[[DERIVED_2]]>
54 ! CHECK: %[[VAL_2:.*]] = fir.zero_bits !fir.ptr<f32>
55 ! CHECK: %[[VAL_3:.*]] = fir.embox %[[VAL_2]] : (!fir.ptr<f32>) -> !fir.box<!fir.ptr<f32>>
56 ! 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]]>
57 ! CHECK: %[[VAL_5:.*]] = fir.field_index y, !fir.type<[[DERIVED_2]]>
58 ! CHECK: %[[VAL_6:.*]] = fir.address_of(@_QFtest_constant_scalar_ptr_componentEtarg) : !fir.ref<!fir.array<100xf32>>
59 ! CHECK: %[[VAL_7:.*]] = arith.constant 100 : index
60 ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1>
61 ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_6]](%[[VAL_8]])
62 ! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index
63 ! CHECK: %[[VAL_13:.*]] = arith.constant 50 : index
64 ! CHECK: %[[VAL_15:.*]] = arith.constant 5 : index
65 ! CHECK: %[[VAL_16:.*]] = arith.constant 10 : index
66 ! CHECK: %[[VAL_17:.*]] = fir.shape %[[VAL_16]] : (index) -> !fir.shape<1>
67 ! 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>>
68 ! CHECK: %[[VAL_19:.*]] = fir.rebox %[[VAL_18]] : (!fir.box<!fir.array<10xf32>>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
69 ! 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]]>
70 ! CHECK: fir.has_value %[[VAL_20]] : !fir.type<[[DERIVED_2]]>