[flang-commits] [flang] [flang][hlfir] Fixed missing deallocation for components of function … (PR #67768)

via flang-commits flang-commits at lists.llvm.org
Fri Sep 29 02:27:41 PDT 2023


================
@@ -451,34 +473,24 @@ fir::ExtendedValue Fortran::lower::genCallOpAndResult(
           fir::runtime::genDerivedTypeDestroy(*bldr, loc,
                                               fir::getBase(*allocatedResult));
         });
-        cleanupWithDestroy = true;
       } else {
         const Fortran::semantics::DerivedTypeSpec &typeSpec =
             retTy->GetDerivedTypeSpec();
-        if (Fortran::semantics::IsFinalizable(typeSpec)) {
+        // If the result type is finalizable or may require finalization
+        // or have allocatable components, we need to make sure
+        // everything is properly finalized/deallocated.
+        if (Fortran::semantics::IsFinalizable(typeSpec) ||
+            Fortran::semantics::MayRequireFinalization(typeSpec) ||
----------------
jeanPerier wrote:

`semantics::MayRequireFinalization` covers IsFinalizable, so you should be able to only call that here.

https://github.com/llvm/llvm-project/pull/67768


More information about the flang-commits mailing list