[flang-commits] [flang] 2d57333 - [flang] Fix crash in HLFIR generation (#118399)

via flang-commits flang-commits at lists.llvm.org
Tue Dec 3 12:11:51 PST 2024


Author: Peter Klausler
Date: 2024-12-03T12:11:47-08:00
New Revision: 2d57333da432921762323718351a21532867588c

URL: https://github.com/llvm/llvm-project/commit/2d57333da432921762323718351a21532867588c
DIFF: https://github.com/llvm/llvm-project/commit/2d57333da432921762323718351a21532867588c.diff

LOG: [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 https://github.com/llvm/llvm-project/issues/118270,
https://github.com/llvm/llvm-project/issues/96994, and
https://github.com/llvm/llvm-project/issues/105848.

Added: 
    

Modified: 
    flang/lib/Lower/ConvertExprToHLFIR.cpp

Removed: 
    


################################################################################
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