xref: /llvm-project/flang/test/Lower/dummy-argument-derived.f90 (revision 3d63d2111c3e8ee2c897caa6d71429e3bf183e2d)
1! Test lowering of derived type dummy arguments
2! RUN: bbc -emit-fir %s -o - | FileCheck %s
3module type_defs
4  type simple_type
5    integer :: i
6  end type
7  type with_kind(k)
8    integer, kind :: k
9    real(k) :: x
10  end type
11end module
12
13! -----------------------------------------------------------------------------
14!     Test passing of derived type arguments that do not require a
15!     fir.box (runtime descriptor).
16! -----------------------------------------------------------------------------
17
18! Test simple type scalar with no attribute.
19! CHECK-LABEL: func @_QPtest1(
20! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.type<_QMtype_defsTsimple_type{i:i32}>> {fir.bindc_name = "a"}) {
21subroutine test1(a)
22  use type_defs
23  type(simple_type) :: a
24end subroutine
25
26! Test simple type explicit array with no attribute.
27! CHECK-LABEL: func @_QPtest2(
28! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.array<100x!fir.type<_QMtype_defsTsimple_type{i:i32}>>> {fir.bindc_name = "a"}) {
29subroutine test2(a)
30  use type_defs
31  type(simple_type) :: a(100)
32end subroutine
33
34! Test simple type scalar with TARGET attribute.
35! CHECK-LABEL: func @_QPtest3(
36! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.type<_QMtype_defsTsimple_type{i:i32}>> {fir.bindc_name = "a", fir.target}) {
37subroutine test3(a)
38  use type_defs
39  type(simple_type), target :: a
40end subroutine
41
42! Test simple type explicit array with TARGET attribute.
43! CHECK-LABEL: func @_QPtest4(
44! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.array<100x!fir.type<_QMtype_defsTsimple_type{i:i32}>>> {fir.bindc_name = "a", fir.target}) {
45subroutine test4(a)
46  use type_defs
47  type(simple_type), target :: a(100)
48end subroutine
49
50! Test kind parametrized derived type scalar with no attribute.
51! CHECK-LABEL: func @_QPtest1k(
52! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.type<_QMtype_defsTwith_kindK4{x:f32}>> {fir.bindc_name = "a"}) {
53subroutine test1k(a)
54  use type_defs
55  type(with_kind(4)) :: a
56end subroutine
57
58! Test kind parametrized derived type explicit array with no attribute.
59! CHECK-LABEL: func @_QPtest2k(
60! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.array<100x!fir.type<_QMtype_defsTwith_kindK4{x:f32}>>> {fir.bindc_name = "a"}) {
61subroutine test2k(a)
62  use type_defs
63  type(with_kind(4)) :: a(100)
64end subroutine
65
66! Test kind parametrized derived type scalar with TARGET attribute.
67! CHECK-LABEL: func @_QPtest3k(
68! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.type<_QMtype_defsTwith_kindK4{x:f32}>> {fir.bindc_name = "a", fir.target}) {
69subroutine test3k(a)
70  use type_defs
71  type(with_kind(4)), target :: a
72end subroutine
73
74! Test kind parametrized derived type explicit array with TARGET attribute.
75! CHECK-LABEL: func @_QPtest4k(
76! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<!fir.array<100x!fir.type<_QMtype_defsTwith_kindK4{x:f32}>>> {fir.bindc_name = "a", fir.target}) {
77subroutine test4k(a)
78  use type_defs
79  type(with_kind(4)), target :: a(100)
80end subroutine
81
82! -----------------------------------------------------------------------------
83!     Test passing of derived type arguments that require a fir.box (runtime descriptor).
84! -----------------------------------------------------------------------------
85
86! Test simple type assumed shape array with no attribute.
87! CHECK-LABEL: func @_QPtest5(
88! CHECK-SAME:  %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.type<_QMtype_defsTsimple_type{i:i32}>>> {fir.bindc_name = "a"}) {
89subroutine test5(a)
90  use type_defs
91  type(simple_type) :: a(:)
92end subroutine
93
94! Test simple type assumed shape array with TARGET attribute.
95! CHECK-LABEL: func @_QPtest6(
96! CHECK-SAME:  %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.type<_QMtype_defsTsimple_type{i:i32}>>> {fir.bindc_name = "a", fir.target}) {
97subroutine test6(a)
98  use type_defs
99  type(simple_type), target :: a(:)
100end subroutine
101
102! Test kind parametrized derived type assumed shape array with no attribute.
103! CHECK-LABEL: func @_QPtest5k(
104! CHECK-SAME:  %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.type<_QMtype_defsTwith_kindK4{x:f32}>>> {fir.bindc_name = "a"}) {
105subroutine test5k(a)
106  use type_defs
107  type(with_kind(4)) :: a(:)
108end subroutine
109
110! Test kind parametrized derived type assumed shape array with TARGET attribute.
111! CHECK-LABEL: func @_QPtest6k(
112! CHECK-SAME:  %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.type<_QMtype_defsTwith_kindK4{x:f32}>>> {fir.bindc_name = "a", fir.target}) {
113subroutine test6k(a)
114  use type_defs
115  type(with_kind(4)), target :: a(:)
116end subroutine
117