[flang-commits] [flang] 5c988cb - [flang] Use derivedType from toAddedum to get updated components

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Feb 16 05:54:21 PST 2023


Author: Valentin Clement
Date: 2023-02-16T14:54:14+01:00
New Revision: 5c988cba4a669051c819730ad0e8fa925056708b

URL: https://github.com/llvm/llvm-project/commit/5c988cba4a669051c819730ad0e8fa925056708b
DIFF: https://github.com/llvm/llvm-project/commit/5c988cba4a669051c819730ad0e8fa925056708b.diff

LOG: [flang] Use derivedType from toAddedum to get updated components

When the rhs is polymorphic and allocated during assignment, the
derivedType might have change from the one set in `toDerived`.
Use the one set in the addendum so it is always up to date.

This can happen in cases like the one shown below:

```
type :: t1
end type t1

type, extends(t1) :: t2
  integer, allocatable :: i(:)
end type

subroutine assign(t)
  class(t2), intent(in) :: t
  class(t1), allocatable :: cp

  cp = t
end subroutine
```

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D144171

Added: 
    

Modified: 
    flang/runtime/assign.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index ca8039b6b0eb9..c93012e03f131 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -313,15 +313,16 @@ static void Assign(Descriptor &to, const Descriptor &from,
         "Assign: mismatching element sizes (to %zd bytes != from %zd bytes)",
         elementBytes, from.ElementBytes());
   }
-  if (toDerived) {
+  if (const typeInfo::DerivedType *
+      updatedToDerived{toAddendum ? toAddendum->derivedType() : nullptr}) {
     // Derived type intrinsic assignment, which is componentwise and elementwise
     // for all components, including parent components (10.2.1.2-3).
     // The target is first finalized if still necessary (7.5.6.3(1))
     if (needFinalization) {
-      Finalize(to, *toDerived);
+      Finalize(to, *updatedToDerived);
     }
     // Copy the data components (incl. the parent) first.
-    const Descriptor &componentDesc{toDerived->component()};
+    const Descriptor &componentDesc{updatedToDerived->component()};
     std::size_t numComponents{componentDesc.Elements()};
     for (std::size_t k{0}; k < numComponents; ++k) {
       const auto &comp{
@@ -394,7 +395,7 @@ static void Assign(Descriptor &to, const Descriptor &from,
       }
     }
     // Copy procedure pointer components
-    const Descriptor &procPtrDesc{toDerived->procPtr()};
+    const Descriptor &procPtrDesc{updatedToDerived->procPtr()};
     std::size_t numProcPtrs{procPtrDesc.Elements()};
     for (std::size_t k{0}; k < numProcPtrs; ++k) {
       const auto &procPtr{


        


More information about the flang-commits mailing list