[flang-commits] [flang] [flang] Fix crash in HLFIR generation (PR #118399)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Dec 2 13:49:26 PST 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/issues/118270.
>From 8f4369f903c8be61d1f77a7c0d67c6d7dd136dec Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Mon, 2 Dec 2024 13:47:09 -0800
Subject: [PATCH] [flang] Fix crash in HLFIR generation
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 https://github.com/llvm/llvm-project/issues/118270.
---
flang/lib/Lower/ConvertExprToHLFIR.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index e93fbc562f9b13..4ab319b016caf7 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<const Fortran::lower::SomeExpr &,
const Fortran::semantics::Symbol &,
hlfir::EntityWithAttributes>;
llvm::SmallVector<ValueAndParent> 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<fir::RecordType>(
More information about the flang-commits
mailing list