[flang-commits] [flang] [flang] ensure parent component are first in runtime type info (PR #81259)

via flang-commits flang-commits at lists.llvm.org
Fri Feb 9 07:54:04 PST 2024


https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/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

>From 7b41c0aff744060c092157ff9a6a43693060c2fa Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Fri, 9 Feb 2024 07:26:45 -0800
Subject: [PATCH] [flang] ensure parent component are first in runtime type
 info

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
---
 flang/lib/Semantics/runtime-type-info.cpp |  5 +++--
 flang/test/Semantics/typeinfo10.f90       | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Semantics/typeinfo10.f90

diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp
index 66c42160ee9e9..9845a190bc756 100644
--- a/flang/lib/Semantics/runtime-type-info.cpp
+++ b/flang/lib/Semantics/runtime-type-info.cpp
@@ -555,10 +555,11 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
           },
           symbol.details());
     }
-    // Sort the data component symbols by offset before emitting them
+    // Sort the data component symbols by offset before emitting them, placing
+    // the parent component first if any.
     std::sort(dataComponentSymbols.begin(), dataComponentSymbols.end(),
         [](const Symbol *x, const Symbol *y) {
-          return x->offset() < y->offset();
+          return x->test(Symbol::Flag::ParentComp) || x->offset() < y->offset();
         });
     std::vector<evaluate::StructureConstructor> dataComponents;
     for (const Symbol *symbol : dataComponentSymbols) {
diff --git a/flang/test/Semantics/typeinfo10.f90 b/flang/test/Semantics/typeinfo10.f90
new file mode 100644
index 0000000000000..43c418bf45d0f
--- /dev/null
+++ b/flang/test/Semantics/typeinfo10.f90
@@ -0,0 +1,14 @@
+!RUN: bbc --dump-symbols %s | FileCheck %s
+!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
+
+! Test that empty parent types are still set first in the
+! runtime info global array describing components.
+module empty_parent
+ type :: z
+ end type
+
+ type, extends(z) :: t
+  integer :: a
+ end type
+end module
+! CHECK: .c.t, SAVE{{.*}}.n.z{{.*}}n.a



More information about the flang-commits mailing list