Skip to content

Commit 2d57333

Browse files
authored
[flang] Fix crash in HLFIR generation (#118399)
Structure constructors with multiple components would crash when components were from parent types. The search for the right parent component must be done anew for each component. Fixes #118270, #96994, and #105848.
1 parent cd04653 commit 2d57333

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

flang/lib/Lower/ConvertExprToHLFIR.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,18 +1696,17 @@ class HlfirBuilder {
16961696
// required chains of hlfir.designate to address the parent components so
16971697
// that the StructureConstructor can later be lowered by addressing these
16981698
// parent components if needed. Note: the front-end orders the components in
1699-
// structure constructors. The code below relies on the component to appear
1700-
// in order.
1699+
// structure constructors.
17011700
using ValueAndParent = std::tuple<const Fortran::lower::SomeExpr &,
17021701
const Fortran::semantics::Symbol &,
17031702
hlfir::EntityWithAttributes>;
17041703
llvm::SmallVector<ValueAndParent> valuesAndParents;
1705-
Fortran::lower::ComponentReverseIterator compIterator(
1706-
ctor.result().derivedTypeSpec());
1707-
hlfir::EntityWithAttributes currentParent = varOp;
17081704
for (const auto &value : llvm::reverse(ctor.values())) {
17091705
const Fortran::semantics::Symbol &compSym = *value.first;
1710-
while (!compIterator.lookup(compSym.name())) {
1706+
hlfir::EntityWithAttributes currentParent = varOp;
1707+
for (Fortran::lower::ComponentReverseIterator compIterator(
1708+
ctor.result().derivedTypeSpec());
1709+
!compIterator.lookup(compSym.name());) {
17111710
const auto &parentType = compIterator.advanceToParentType();
17121711
llvm::StringRef parentName = toStringRef(parentType.name());
17131712
auto baseRecTy = mlir::cast<fir::RecordType>(

0 commit comments

Comments
 (0)