[flang-commits] [flang] [flang] Fix use-after-free in `MemoryAllocation.cpp` (PR #83768)

via flang-commits flang-commits at lists.llvm.org
Sun Mar 3 21:59:16 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Matthias Springer (matthias-springer)

<details>
<summary>Changes</summary>

`AllocaOpConversion` takes an `ArrayRef<Operation *>`, but the underlying `SmallVector<Operation *>` was dead by the time the pattern ran.

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


1 Files Affected:

- (modified) flang/lib/Optimizer/Transforms/MemoryAllocation.cpp (+2-1) 


``````````diff
diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
index f0e201402fa79c..166a6b10def293 100644
--- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
+++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
@@ -200,7 +200,8 @@ class MemoryAllocationOpt
       return keepStackAllocation(alloca, &func.front(), options);
     });
 
-    patterns.insert<AllocaOpConversion>(context, analysis.getReturns(func));
+    llvm::SmallVector<mlir::Operation *> returnOps = analysis.getReturns(func);
+    patterns.insert<AllocaOpConversion>(context, returnOps);
     if (mlir::failed(
             mlir::applyPartialConversion(func, target, std::move(patterns)))) {
       mlir::emitError(func.getLoc(),

``````````

</details>


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


More information about the flang-commits mailing list