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

Matthias Springer via flang-commits flang-commits at lists.llvm.org
Sun Mar 3 21:58:43 PST 2024


https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/83768

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

>From ac0eceef06dc5e645e912af8f58ac35f9b00a945 Mon Sep 17 00:00:00 2001
From: Matthias Springer <springerm at google.com>
Date: Mon, 4 Mar 2024 05:56:58 +0000
Subject: [PATCH] [flang] Fix use-after-free in `MemoryAllocation.cpp`

`AllocaOpConversion` takes an `ArrayRef<Operation *>`, but the
underlying `SmallVector<Operation *>` was dead by the time the pattern
ran.
---
 flang/lib/Optimizer/Transforms/MemoryAllocation.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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(),



More information about the flang-commits mailing list