Skip to content

Commit 0b3d549

Browse files
authored
[flang][hlfir] Lower parent component in constant structure constructors (llvm#71421)
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.
1 parent a700a52 commit 0b3d549

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

flang/lib/Lower/ConvertConstant.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@ static mlir::Value genInlinedStructureCtorLitImpl(
476476

477477
const Fortran::semantics::DerivedTypeSpec *curentType = nullptr;
478478
for (const auto &[sym, expr] : ctor.values()) {
479-
// This TODO is not needed here anymore, but should be removed in a separate
480-
// patch.
481-
if (sym->test(Fortran::semantics::Symbol::Flag::ParentComp))
482-
TODO(loc, "parent component in structure constructor");
483479
const Fortran::semantics::DerivedTypeSpec *componentParentType =
484480
sym->owner().derivedTypeSpec();
485481
assert(componentParentType && "failed to retrieve component parent type");

flang/test/Lower/HLFIR/constant-derived.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ subroutine test_constant_scalar_ptr_component()
2424
! CHECK: fir.address_of(@[[CST_TARGET:_QQro._QFtest_constant_scalar_ptr_componentTmyderived..*]])
2525
end subroutine
2626

27+
subroutine test_comp_ref()
28+
! Test parent component value in an initial value structure constructor.
29+
type t1
30+
integer :: i
31+
end type
32+
type, extends(t1) :: t2
33+
integer :: j
34+
end type
35+
type(t2) :: x = t2(t1=t1(1), j=2)
36+
end subroutine
37+
2738
! 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>}]]> {
2839
! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<[[DERIVED]]>
2940
! CHECK: %[[VAL_1:.*]] = fir.field_index i, !fir.type<[[DERIVED]]>
@@ -69,3 +80,17 @@ subroutine test_constant_scalar_ptr_component()
6980
! 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]]>
7081
! CHECK: fir.has_value %[[VAL_20]] : !fir.type<[[DERIVED_2]]>
7182
! CHECK: }
83+
84+
! CHECK-LABEL: fir.global internal @_QFtest_comp_refEx : !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}> {
85+
! CHECK: %[[VAL_0:.*]] = fir.undefined !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
86+
! CHECK: %[[VAL_1:.*]] = fir.field_index t1, !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
87+
! CHECK: %[[VAL_2:.*]] = fir.undefined !fir.type<_QFtest_comp_refTt1{i:i32}>
88+
! CHECK: %[[VAL_3:.*]] = fir.field_index i, !fir.type<_QFtest_comp_refTt1{i:i32}>
89+
! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
90+
! 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}>
91+
! 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}>
92+
! CHECK: %[[VAL_7:.*]] = fir.field_index j, !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
93+
! CHECK: %[[VAL_8:.*]] = arith.constant 2 : i32
94+
! 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}>
95+
! CHECK: fir.has_value %[[VAL_9]] : !fir.type<_QFtest_comp_refTt2{t1:!fir.type<_QFtest_comp_refTt1{i:i32}>,j:i32}>
96+
! CHECK: }

0 commit comments

Comments
 (0)