[llvm] [flang][runtime] Accomodate change of type in assignment to allocatable (PR #141988)

Peter Klausler via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 10:05:11 PDT 2025


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/141988

When an assignment to a derived type allocatable requires (re)allocation, its type may change to that of the right-hand side.  The code didn't update its derived type pointer, leading to the wrong type being put into the descriptors created for elemental defined assignment subroutine calls.

Fixes https://github.com/llvm/llvm-project/issues/141835.

>From d67c77d76655af5aa691fb5be238448bb5a74ac9 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Thu, 29 May 2025 10:00:51 -0700
Subject: [PATCH] [flang][runtime] Accomodate change of type in assignment to
 allocatable

When an assignment to a derived type allocatable requires (re)allocation,
its type may change to that of the right-hand side.  The code didn't
update its derived type pointer, leading to the wrong type being
put into the descriptors created for elemental defined assignment
subroutine calls.

Fixes https://github.com/llvm/llvm-project/issues/141835.
---
 flang-rt/lib/runtime/assign.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/flang-rt/lib/runtime/assign.cpp b/flang-rt/lib/runtime/assign.cpp
index 86aeeaa88f2d1..bf67b5dc8b645 100644
--- a/flang-rt/lib/runtime/assign.cpp
+++ b/flang-rt/lib/runtime/assign.cpp
@@ -330,6 +330,7 @@ RT_API_ATTRS void Assign(Descriptor &to, const Descriptor &from,
       }
       flags &= ~NeedFinalization;
       toElementBytes = to.ElementBytes(); // may have changed
+      toDerived = toAddendum ? toAddendum->derivedType() : nullptr;
     }
   }
   if (toDerived && (flags & CanBeDefinedAssignment)) {



More information about the llvm-commits mailing list