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

via flang-commits flang-commits at lists.llvm.org
Sun Mar 3 22:54:26 PST 2024


Author: Matthias Springer
Date: 2024-03-04T15:54:22+09:00
New Revision: 354deba10a99136a3204dfa8128e53cd6e9558a7

URL: https://github.com/llvm/llvm-project/commit/354deba10a99136a3204dfa8128e53cd6e9558a7
DIFF: https://github.com/llvm/llvm-project/commit/354deba10a99136a3204dfa8128e53cd6e9558a7.diff

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

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

Added: 
    

Modified: 
    flang/lib/Optimizer/Transforms/MemoryAllocation.cpp

Removed: 
    


################################################################################
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