xref: /llvm-project/flang/test/Semantics/offsets02.f90 (revision 08d6b8745430e133cc9d257cded623229e58fddd)
1!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
2
3! Size and alignment of derived types
4
5! Array of derived type with 64-bit alignment
6subroutine s1
7  type t1
8    real(8) :: a
9    real(4) :: b
10  end type
11  type t2
12    type(t1) c
13    real(4) d
14  end type
15  !CHECK: x1 size=16 offset=0:
16  !CHECK: y1 size=16 offset=16:
17  type(t1) :: x1, y1
18  !CHECK: z1 size=160 offset=32:
19  type(t1) :: z1(10)
20  !CHECK: z2 size=24 offset=192
21  type(t2) z2
22end
23
24! Like t1 but t2 does not need to be aligned on 64-bit boundary
25subroutine s2
26  type t2
27    real(4) :: a
28    real(4) :: b
29    real(4) :: c
30  end type
31  !CHECK: x2 size=12 offset=0:
32  !CHECK: y2 size=12 offset=12:
33  type(t2) :: x2, y2
34  !CHECK: z2 size=120 offset=24:
35  type(t2) :: z2(10)
36end
37
38! Parameterized derived types
39subroutine s3
40  type :: t(k, l)
41    integer, kind :: k
42    integer, len :: l
43    real(k) :: a3
44    integer(kind=k) :: b3
45    character(kind=k, len=8) :: c3
46    character(kind=k, len=l) :: d3
47  end type
48  !CHECK: DerivedType scope: size=48 alignment=8 instantiation of t(k=2_4,l=10_4)
49  !CHECK: a3 size=2 offset=0:
50  !CHECK: b3 size=2 offset=2:
51  !CHECK: c3 size=16 offset=4:
52  !CHECK: d3 size=24 offset=24:
53  type(t(2, 10)) :: x3
54  !CHECK: DerivedType scope: size=64 alignment=8 instantiation of t(k=4_4,l=20_4)
55  !CHECK: a3 size=4 offset=0:
56  !CHECK: b3 size=4 offset=4:
57  !CHECK: c3 size=32 offset=8:
58  !CHECK: d3 size=24 offset=40:
59  type(t(4, 20)) :: x4
60end
61
62subroutine s4
63  type t(k)
64    integer, kind :: k
65    character(len=k) :: c
66  end type
67  type(t(7)) :: x4
68  !CHECK: DerivedType scope: size=7 alignment=1 instantiation of t(k=7_4)
69  !CHECK: c size=7 offset=0: ObjectEntity type: CHARACTER(7_4,1)
70end subroutine
71