Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] ensure parent component are first in runtime type info #81259

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

jeanPerier
Copy link
Contributor

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

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
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 9, 2024

@llvm/pr-subscribers-flang-semantics

Author: None (jeanPerier)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/81259.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/runtime-type-info.cpp (+3-2)
  • (added) flang/test/Semantics/typeinfo10.f90 (+14)
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

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you!

@jeanPerier jeanPerier merged commit 53c260d into llvm:main Feb 12, 2024
7 checks passed
@jeanPerier jeanPerier deleted the jpr-fix-parent-comp branch February 12, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants