Skip to content

Commit 53c260d

Browse files
authored
[flang] ensure parent component are first in runtime type info (#81259)
Static info generated to describe derived types contain an array listing the components of some derived type. The parent component must be first for the runtime to properly works. The current sort was only relying on the offset, but if the parent is an empty type, this did not work properly because its offset did not compare smaller than the first component and the parent was not added first
1 parent b726a81 commit 53c260d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

flang/lib/Semantics/runtime-type-info.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,11 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
555555
},
556556
symbol.details());
557557
}
558-
// Sort the data component symbols by offset before emitting them
558+
// Sort the data component symbols by offset before emitting them, placing
559+
// the parent component first if any.
559560
std::sort(dataComponentSymbols.begin(), dataComponentSymbols.end(),
560561
[](const Symbol *x, const Symbol *y) {
561-
return x->offset() < y->offset();
562+
return x->test(Symbol::Flag::ParentComp) || x->offset() < y->offset();
562563
});
563564
std::vector<evaluate::StructureConstructor> dataComponents;
564565
for (const Symbol *symbol : dataComponentSymbols) {

flang/test/Semantics/typeinfo10.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!RUN: bbc --dump-symbols %s | FileCheck %s
2+
!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
3+
4+
! Test that empty parent types are still set first in the
5+
! runtime info global array describing components.
6+
module empty_parent
7+
type :: z
8+
end type
9+
10+
type, extends(z) :: t
11+
integer :: a
12+
end type
13+
end module
14+
! CHECK: .c.t, SAVE{{.*}}.n.z{{.*}}n.a

0 commit comments

Comments
 (0)