Skip to content

Commit 08d6b87

Browse files
authored
[flang] Round derived type byte sizes up to alignment multiple (#67571)
When calculating sizes and offsets of types and components, be sure to round the size of a derived type up to a multiple of its alignment.
1 parent 7cad5a9 commit 08d6b87

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

flang/lib/Semantics/compute-offsets.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ void ComputeOffsetsHelper::Compute(Scope &scope) {
116116
DoSymbol(*symbol);
117117
}
118118
}
119+
// Ensure that the size is a multiple of the alignment
120+
offset_ = Align(offset_, alignment_);
119121
scope.set_size(offset_);
120122
scope.SetAlignment(alignment_);
121123
// Assign offsets in COMMON blocks, unless this scope is a BLOCK construct,

flang/test/Semantics/offsets02.f90

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ subroutine s1
88
real(8) :: a
99
real(4) :: b
1010
end type
11-
!CHECK: x1 size=12 offset=0:
12-
!CHECK: y1 size=12 offset=16:
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:
1317
type(t1) :: x1, y1
1418
!CHECK: z1 size=160 offset=32:
1519
type(t1) :: z1(10)
20+
!CHECK: z2 size=24 offset=192
21+
type(t2) z2
1622
end
1723

1824
! Like t1 but t2 does not need to be aligned on 64-bit boundary

0 commit comments

Comments
 (0)