[flang-commits] [flang] [flang] keep runtime allocator for pinned allocations (PR #207822)

via flang-commits flang-commits at lists.llvm.org
Mon Jul 6 12:48:02 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: yebinchon

<details>
<summary>Changes</summary>

If an allocatable is pinned, use the flang runtime instead of lowering to normal memcpy/free.

---
Full diff: https://github.com/llvm/llvm-project/pull/207822.diff


1 Files Affected:

- (modified) flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp (+8) 


``````````diff
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
index 0160ff7d75f76..cf56025d9be43 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
@@ -76,6 +76,14 @@ class SeparateAllocatableAssignConversion
     if (!fir::isBoxAddress(lhs.getType()))
       return rewriter.notifyMatchFailure(assign, "LHS is not a box address");
 
+    // If the LHS allocatable is backed by a non-default (CUF) allocator
+    // (pinned/device/managed/unified), its (re)allocation must go through the
+    // Fortran runtime so the allocator recorded in the descriptor is honored.
+    if (mlir::Operation *lhsDef = assign.getLhs().getDefiningOp())
+      if (cuf::getDataAttr(lhsDef))
+        return rewriter.notifyMatchFailure(
+            assign, "LHS uses a non-default allocator; keep runtime realloc");
+
     mlir::Location loc = assign->getLoc();
     fir::FirOpBuilder builder(rewriter, assign.getOperation());
     builder.setInsertionPoint(assign);

``````````

</details>


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


More information about the flang-commits mailing list