[llvm] [flang] Clear obsolete type from reallocated allocatable (PR #139788)
Peter Klausler via llvm-commits
llvm-commits at lists.llvm.org
Tue May 13 13:18:16 PDT 2025
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/139788
When an assignment to a polymorphic allocatable changes its type to an intrinsic type, be sure to reset its descriptor's derived type pointer to null.
Fixes https://github.com/llvm/llvm-project/issues/136522.
>From a302027daae3d380958046453c306c90be4fb283 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 13 May 2025 13:15:57 -0700
Subject: [PATCH] [flang] Clear obsolete type from reallocated allocatable
When an assignment to a polymorphic allocatable changes its
type to an intrinsic type, be sure to reset its descriptor's
derived type pointer to null.
Fixes https://github.com/llvm/llvm-project/issues/136522.
---
flang-rt/lib/runtime/assign.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/flang-rt/lib/runtime/assign.cpp b/flang-rt/lib/runtime/assign.cpp
index 4a813cd489022..9be75da9520e3 100644
--- a/flang-rt/lib/runtime/assign.cpp
+++ b/flang-rt/lib/runtime/assign.cpp
@@ -79,15 +79,18 @@ static RT_API_ATTRS int AllocateAssignmentLHS(
to.raw().elem_len = from.ElementBytes();
}
const typeInfo::DerivedType *derived{nullptr};
+ DescriptorAddendum *toAddendum{to.Addendum()};
if (const DescriptorAddendum * fromAddendum{from.Addendum()}) {
derived = fromAddendum->derivedType();
- if (DescriptorAddendum * toAddendum{to.Addendum()}) {
+ if (toAddendum) {
toAddendum->set_derivedType(derived);
std::size_t lenParms{derived ? derived->LenParameters() : 0};
for (std::size_t j{0}; j < lenParms; ++j) {
toAddendum->SetLenParameterValue(j, fromAddendum->LenParameterValue(j));
}
}
+ } else if (toAddendum) {
+ toAddendum->set_derivedType(nullptr);
}
// subtle: leave bounds in place when "from" is scalar (10.2.1.3(3))
int rank{from.rank()};
More information about the llvm-commits
mailing list