[llvm] 96ad51e - [StructurizeCFG][DebugInfo] Avoid use-after-free

Juan Manuel MARTINEZ CAAMAÑO via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 06:40:11 PDT 2022


Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2022-11-04T13:39:49Z
New Revision: 96ad51e3ebafdaed345a699d752ee4d96b00d82c

URL: https://github.com/llvm/llvm-project/commit/96ad51e3ebafdaed345a699d752ee4d96b00d82c
DIFF: https://github.com/llvm/llvm-project/commit/96ad51e3ebafdaed345a699d752ee4d96b00d82c.diff

LOG: [StructurizeCFG][DebugInfo] Avoid use-after-free

Reviewed By: dstuttard

Differential Revision: https://reviews.llvm.org/D137408

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
index 2adf172f6b98..81d151c2904e 100644
--- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -856,7 +856,12 @@ BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) {
   BasicBlock *Flow = BasicBlock::Create(Context, FlowBlockName,
                                         Func, Insert);
   FlowSet.insert(Flow);
-  TermDL[Flow] = TermDL[Dominator];
+
+  // use a temporary variable to avoid a use-after-free if the map's storage is
+  // reallocated
+  DebugLoc DL = TermDL[Dominator];
+  TermDL[Flow] = std::move(DL);
+
   DT->addNewBlock(Flow, Dominator);
   ParentRegion->getRegionInfo()->setRegionFor(Flow, ParentRegion);
   return Flow;


        


More information about the llvm-commits mailing list