[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 06:40:26 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG96ad51e3ebaf: [StructurizeCFG][DebugInfo] Avoid use-after-free (authored by jmmartinez).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137408/new/

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.473219.patch
Type: text/x-patch
Size: 718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/d440c27e/attachment.bin>


More information about the llvm-commits mailing list