Skip to content

Commit

Permalink
[flang] Round derived type byte sizes up to alignment multiple (#67571)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klausler committed Oct 17, 2023
1 parent 7cad5a9 commit 08d6b87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions flang/lib/Semantics/compute-offsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void ComputeOffsetsHelper::Compute(Scope &scope) {
DoSymbol(*symbol);
}
}
// Ensure that the size is a multiple of the alignment
offset_ = Align(offset_, alignment_);
scope.set_size(offset_);
scope.SetAlignment(alignment_);
// Assign offsets in COMMON blocks, unless this scope is a BLOCK construct,
Expand Down
10 changes: 8 additions & 2 deletions flang/test/Semantics/offsets02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ subroutine s1
real(8) :: a
real(4) :: b
end type
!CHECK: x1 size=12 offset=0:
!CHECK: y1 size=12 offset=16:
type t2
type(t1) c
real(4) d
end type
!CHECK: x1 size=16 offset=0:
!CHECK: y1 size=16 offset=16:
type(t1) :: x1, y1
!CHECK: z1 size=160 offset=32:
type(t1) :: z1(10)
!CHECK: z2 size=24 offset=192
type(t2) z2
end

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

0 comments on commit 08d6b87

Please sign in to comment.