[llvm] 2eb96e1 - [DebugInfo][NFC] Avoid a use-after-free
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 25 06:16:39 PDT 2021
Author: Jeremy Morse
Date: 2021-10-25T14:16:30+01:00
New Revision: 2eb96e1711bf6ae03351c7ba9d7ce8a40f6aa21c
URL: https://github.com/llvm/llvm-project/commit/2eb96e1711bf6ae03351c7ba9d7ce8a40f6aa21c
DIFF: https://github.com/llvm/llvm-project/commit/2eb96e1711bf6ae03351c7ba9d7ce8a40f6aa21c.diff
LOG: [DebugInfo][NFC] Avoid a use-after-free
This patch swaps two lines -- the CurSucc reference can be invalidated
by the call to DFS.push_back, therefore that should happen last. The
usual hat-tip to asan for catching this.
This patch also swaps an ealier call to ToAdd.insert and DFS.push_back,
where a stable iterator (from successors()) is being used. This isn't
strictly necessary, but is good for consistency and avoiding readers
asking themselves why the two code portions have a different order.
Added:
Modified:
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 7fd023d1b5583..dda9b876a7f38 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -2367,8 +2367,8 @@ void InstrRefBasedLDV::buildVLocValueMap(const DILocation *DILoc,
continue;
if (!ArtificialBlocks.count(succ))
continue;
- DFS.push_back(std::make_pair(succ, succ->succ_begin()));
ToAdd.insert(succ);
+ DFS.push_back(std::make_pair(succ, succ->succ_begin()));
}
// Search all those blocks, depth first.
@@ -2384,8 +2384,8 @@ void InstrRefBasedLDV::buildVLocValueMap(const DILocation *DILoc,
// If the current successor is artificial and unexplored, descend into
// it.
if (!ToAdd.count(*CurSucc) && ArtificialBlocks.count(*CurSucc)) {
- DFS.push_back(std::make_pair(*CurSucc, (*CurSucc)->succ_begin()));
ToAdd.insert(*CurSucc);
+ DFS.push_back(std::make_pair(*CurSucc, (*CurSucc)->succ_begin()));
continue;
}
More information about the llvm-commits
mailing list