[PATCH] D137408: [StructurizeCFG][DebugInfo] Avoid use-after-free

Juan Manuel Martinez CaamaƱo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 04:33:43 PDT 2022


jmmartinez created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jmmartinez requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137408

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


Index: llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
+++ llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -856,7 +856,12 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137408.473191.patch
Type: text/x-patch
Size: 718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/499c2090/attachment.bin>


More information about the llvm-commits mailing list