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][hlfir] Lower parent component in constant structure constructors #71421

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

jeanPerier
Copy link
Contributor

Simply remove TODO. Since parent components are now fields of the extended types fir.type<> in HLFIR, there is nothing specific to do to deal with the appearance of a parent component value in a structure constructor value that must be turned into a fir.global initial value: it can simply be inserted as a normal field value.

Remove TODO, since parent components are now a field of the record type
in FIR, there is nothing specific to do to deal with their appearance
in a structure constructor value that must be turned into a fir.global
initial value.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Nov 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-flang-fir-hlfir

Author: None (jeanPerier)

Changes

Simply remove TODO. Since parent components are now fields of the extended types fir.type<> in HLFIR, there is nothing specific to do to deal with the appearance of a parent component value in a structure constructor value that must be turned into a fir.global initial value: it can simply be inserted as a normal field value.


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

2 Files Affected:

  • (modified) flang/lib/Lower/ConvertConstant.cpp (-4)
  • (modified) flang/test/Lower/HLFIR/constant-derived.f90 (+25)
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index 423a14de4b0a9ca..56ca7ab2d93103c 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -476,10 +476,6 @@ static mlir::Value genInlinedStructureCtorLitImpl(
 
   const Fortran::semantics::DerivedTypeSpec *curentType = nullptr;
   for (const auto &[sym, expr] : ctor.values()) {
-    // This TODO is not needed here anymore, but should be removed in a separate
-    // patch.
-    if (sym->test(Fortran::semantics::Symbol::Flag::ParentComp))
-      TODO(loc, "parent component in structure constructor");
     const Fortran::semantics::DerivedTypeSpec *componentParentType =
         sym->owner().derivedTypeSpec();
     assert(componentParentType && "failed to retrieve component parent type");
diff --git a/flang/test/Lower/HLFIR/constant-derived.f90 b/flang/test/Lower/HLFIR/constant-derived.f90
index b813da33f3f6c4f..eee3eacdd7aff3c 100644
--- a/flang/test/Lower/HLFIR/constant-derived.f90
+++ b/flang/test/Lower/HLFIR/constant-derived.f90
@@ -24,6 +24,17 @@ subroutine test_constant_scalar_ptr_component()
 ! CHECK:  fir.address_of(@[[CST_TARGET:_QQro._QFtest_constant_scalar_ptr_componentTmyderived..*]])
 end subroutine
 
+subroutine test_comp_ref()
+  ! Test parent component value in an initial value structure constructor.
+  type t1
+    integer :: i
+  end type
+  type, extends(t1) :: t2
+    integer :: j
+  end type
+  type(t2) :: x = t2(t1=t1(1), j=2)
+end subroutine
+
 ! CHECK: fir.global internal @[[CST]] constant : !fir.type<[[DERIVED:_QFtest_constant_scalarTmyderived{i:i32,j:i32,x:!fir.array<2xf32>,c:!fir.char<1,10>}]]> {
 ! CHECK:   %[[VAL_0:.*]] = fir.undefined !fir.type<[[DERIVED]]>
 ! CHECK:   %[[VAL_1:.*]] = fir.field_index i, !fir.type<[[DERIVED]]>
@@ -69,3 +80,17 @@ subroutine test_constant_scalar_ptr_component()
 ! CHECK:   %[[VAL_20:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_19]], ["y", !fir.type<[[DERIVED_2]]>] : (!fir.type<[[DERIVED_2]]>, !fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.type<[[DERIVED_2]]>
 ! CHECK:   fir.has_value %[[VAL_20]] : !fir.type<[[DERIVED_2]]>
 ! CHECK: }
+
+! CHECK-LABEL:   fir.global internal @_QFtest_comp_refEx : !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}> {
+! CHECK:   %[[VAL_0:.*]] = fir.undefined !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
+! CHECK:   %[[VAL_1:.*]] = fir.field_index t1, !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
+! CHECK:   %[[VAL_2:.*]] = fir.undefined !fir.type<_QFtest_comp_refTt1{i:i32}>
+! CHECK:   %[[VAL_3:.*]] = fir.field_index i, !fir.type<_QFtest_comp_refTt1{i:i32}>
+! CHECK:   %[[VAL_4:.*]] = arith.constant 1 : i32
+! CHECK:   %[[VAL_5:.*]] = fir.insert_value %[[VAL_2]], %[[VAL_4]], ["i", !fir.type<_QFtest_comp_refTt1{i:i32}>] : (!fir.type<_QFtest_comp_refTt1{i:i32}>, i32) -> !fir.type<_QFtest_comp_refTt1{i:i32}>
+! CHECK:   %[[VAL_6:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_5]], ["t1", !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>] : (!fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>, !fir.type<_QFtest_comp_refTt1{i:i32}>) -> !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
+! CHECK:   %[[VAL_7:.*]] = fir.field_index j, !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
+! CHECK:   %[[VAL_8:.*]] = arith.constant 2 : i32
+! CHECK:   %[[VAL_9:.*]] = fir.insert_value %[[VAL_6]], %[[VAL_8]], ["j", !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>] : (!fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>, i32) -> !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
+! CHECK:   fir.has_value %[[VAL_9]] : !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
+! CHECK: }

Copy link
Contributor

@clementval clementval left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

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

Looks great!

@jeanPerier jeanPerier merged commit 0b3d549 into llvm:main Nov 7, 2023
5 checks passed
@jeanPerier jeanPerier deleted the jpr-parent-comp branch November 7, 2023 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants