[flang-commits] [flang] 1aff61e - [flang][runtime] Initialize LHS temporary in AssignTemporary.

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Wed May 3 09:19:42 PDT 2023


Author: Slava Zakharin
Date: 2023-05-03T09:19:35-07:00
New Revision: 1aff61ecbfa359929710ade5bd8320f71c40539c

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

LOG: [flang][runtime] Initialize LHS temporary in AssignTemporary.

If LHS is of derived type that needs initialization, then it must be
initialized before doing the assignment. Otherwise, the assignment
might behave incorrectly based on uninitialized components that are
descriptors themselves.

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

Added: 
    

Modified: 
    flang/runtime/assign.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index 0b64020811bca..88f5500588bfa 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -546,6 +546,17 @@ void RTNAME(Assign)(Descriptor &to, const Descriptor &from,
 void RTNAME(AssignTemporary)(Descriptor &to, const Descriptor &from,
     const char *sourceFile, int sourceLine) {
   Terminator terminator{sourceFile, sourceLine};
+  // Initialize the "to" if it is of derived type that needs initialization.
+  if (const DescriptorAddendum * addendum{to.Addendum()}) {
+    if (const auto *derived{addendum->derivedType()}) {
+      if (!derived->noInitializationNeeded()) {
+        if (ReturnError(terminator, Initialize(to, *derived, terminator)) !=
+            StatOk) {
+          return;
+        }
+      }
+    }
+  }
   Assign(to, from, terminator, PolymorphicLHS);
 }
 


        


More information about the flang-commits mailing list