aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
diff options
context:
space:
mode:
authorJonas Hahnfeld <jonas.hahnfeld@cern.ch>2024-10-30 13:56:27 +0100
committerGitHub <noreply@github.com>2024-10-30 13:56:27 +0100
commitc4e135ec04a2bef5d5a5a69dfbb069a15dbf2f5e (patch)
tree6dcf98ec7e44254267a6cc25ca43a4c4b5281233 /llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
parent217700baf760ea3959d79c2090e7930144b698a1 (diff)
downloadllvm-c4e135ec04a2bef5d5a5a69dfbb069a15dbf2f5e.zip
llvm-c4e135ec04a2bef5d5a5a69dfbb069a15dbf2f5e.tar.gz
llvm-c4e135ec04a2bef5d5a5a69dfbb069a15dbf2f5e.tar.bz2
[ORC] Fix transfer to unknown ResourceTrackers (#114063)
When transferring resources, the destination tracker key may not be in the internal map, invalidating iterators and value references. The added test creates such situation and would fail before with "Finalized allocation was not deallocated." For good measure, fix the same pattern in RTDyldObjectLinkingLayer which is harder to test because it "only" results in memory managers being deleted in the wrong order.
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index 25ab154..86c08cb 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -701,16 +701,15 @@ Error ObjectLinkingLayer::handleRemoveResources(JITDylib &JD, ResourceKey K) {
void ObjectLinkingLayer::handleTransferResources(JITDylib &JD,
ResourceKey DstKey,
ResourceKey SrcKey) {
- auto I = Allocs.find(SrcKey);
- if (I != Allocs.end()) {
- auto &SrcAllocs = I->second;
+ if (Allocs.contains(SrcKey)) {
+ // DstKey may not be in the DenseMap yet, so the following line may resize
+ // the container and invalidate iterators and value references.
auto &DstAllocs = Allocs[DstKey];
+ auto &SrcAllocs = Allocs[SrcKey];
DstAllocs.reserve(DstAllocs.size() + SrcAllocs.size());
for (auto &Alloc : SrcAllocs)
DstAllocs.push_back(std::move(Alloc));
- // Erase SrcKey entry using value rather than iterator I: I may have been
- // invalidated when we looked up DstKey.
Allocs.erase(SrcKey);
}