[flang-commits] [flang] [flang] fix early free of allocatable function result in WHERE mask (PR #178691)

via flang-commits flang-commits at lists.llvm.org
Wed Feb 4 03:28:09 PST 2026


================
@@ -1973,17 +1975,28 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals,
   if (!resultIsFinalized) {
     hlfir::Entity resultEntity = extendedValueToHlfirEntity(
         loc, builder, result, tempResultName, /*insertBefore=*/callOp);
+    // Allocatable result must be freed, other results are stack allocated.
+    const auto *allocatable = result.getBoxOf<fir::MutableBoxValue>();
+    bool mustFree = allocatable != nullptr;
----------------
jeanPerier wrote:

```suggestion
    const bool mustFree = allocatable != nullptr;
```

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


More information about the flang-commits mailing list