[flang-commits] [flang] da3e477 - [flang] Avoid double finalization in Assign

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Feb 2 09:03:29 PST 2023


Author: Valentin Clement
Date: 2023-02-02T18:03:19+01:00
New Revision: da3e4770883d2b7ba2269a663cdb9aaaa2e7ee69

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

LOG: [flang] Avoid double finalization in Assign

First call to Assign is issuing finalization for the
LHS and its components. Avoid calling finalization for components
again when doing the component by component assignment.

Reviewed By: klausler

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

Added: 
    

Modified: 
    flang/runtime/assign.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index 741049aa9207..74f4844c39e2 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -68,7 +68,8 @@ static void DoElementalDefinedAssignment(const Descriptor &to,
 // Do not perform allocatable reallocation if \p skipRealloc is true, which is
 // used for allocate statement with source specifier.
 static void Assign(Descriptor &to, const Descriptor &from,
-    Terminator &terminator, bool skipRealloc = false) {
+    Terminator &terminator, bool skipRealloc = false,
+    bool skipFinalization = false) {
   DescriptorAddendum *toAddendum{to.Addendum()};
   const typeInfo::DerivedType *toDerived{
       toAddendum ? toAddendum->derivedType() : nullptr};
@@ -184,7 +185,8 @@ static void Assign(Descriptor &to, const Descriptor &from,
     // 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 (!wasJustAllocated && !toDerived->noFinalizationNeeded()) {
+    if (!wasJustAllocated && !toDerived->noFinalizationNeeded() &&
+        !skipFinalization) {
       Finalize(to, *toDerived);
     }
     // Copy the data components (incl. the parent) first.
@@ -205,7 +207,8 @@ static void Assign(Descriptor &to, const Descriptor &from,
             comp.CreatePointerDescriptor(toCompDesc, to, terminator, toAt);
             comp.CreatePointerDescriptor(
                 fromCompDesc, from, terminator, fromAt);
-            Assign(toCompDesc, fromCompDesc, terminator, /*skipRealloc=*/false);
+            Assign(toCompDesc, fromCompDesc, terminator, /*skipRealloc=*/false,
+                /*skipFinalization=*/true);
           }
         } else { // Component has intrinsic type; simply copy raw bytes
           std::size_t componentByteSize{comp.SizeInBytes(to)};


        


More information about the flang-commits mailing list