diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp index e93fbc562f9b1..4ab319b016caf 100644 --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -1696,18 +1696,17 @@ class HlfirBuilder { // required chains of hlfir.designate to address the parent components so // that the StructureConstructor can later be lowered by addressing these // parent components if needed. Note: the front-end orders the components in - // structure constructors. The code below relies on the component to appear - // in order. + // structure constructors. using ValueAndParent = std::tuple; llvm::SmallVector valuesAndParents; - Fortran::lower::ComponentReverseIterator compIterator( - ctor.result().derivedTypeSpec()); - hlfir::EntityWithAttributes currentParent = varOp; for (const auto &value : llvm::reverse(ctor.values())) { const Fortran::semantics::Symbol &compSym = *value.first; - while (!compIterator.lookup(compSym.name())) { + hlfir::EntityWithAttributes currentParent = varOp; + for (Fortran::lower::ComponentReverseIterator compIterator( + ctor.result().derivedTypeSpec()); + !compIterator.lookup(compSym.name());) { const auto &parentType = compIterator.advanceToParentType(); llvm::StringRef parentName = toStringRef(parentType.name()); auto baseRecTy = mlir::cast(