<div dir="ltr">Found by an out-of-tree user. Unfortunately this only shows up when we exercise the resource-transfer APIs, which none of our existing regression test infrastructure exercises, so there's no easy way to write a testcase for it yet.<div><br></div><div>I'm revisiting unit tests for some of the more obscure JIT APIs (see e.g. the recent C API unit test) -- If I'm able to work the kinks out of those then I'll look at writing a unit test for this.</div><div><br><div>-- Lang.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 2, 2021 at 12:31 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Was this covered by existing tests/found by a novel UB failure on a buildbot or the like?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 25, 2021 at 6:04 PM Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Author: Lang Hames<br>
Date: 2021-04-25T16:55:19-07:00<br>
New Revision: c1baf946e6cf611ae871e34db5cfea0f94f4b5a0<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/c1baf946e6cf611ae871e34db5cfea0f94f4b5a0" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/c1baf946e6cf611ae871e34db5cfea0f94f4b5a0</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/c1baf946e6cf611ae871e34db5cfea0f94f4b5a0.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/c1baf946e6cf611ae871e34db5cfea0f94f4b5a0.diff</a><br>
<br>
LOG: [ORC] Avoid invalidating iterators in EHFrameRegistrationPlugin.<br>
<br>
In EHFrameRegistrationPlugin::notifyTransferringResources if SrcKey had<br>
eh-frames associated but DstKey did not we would create a new entry for DskKey,<br>
invalidating the iterator for SrcKey in the process. This commit fixes that by<br>
removing SrcKey first in this case.<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp<br>
index dc3cf87798cf..ccac4b8c545b 100644<br>
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp<br>
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp<br>
@@ -654,13 +654,23 @@ Error EHFrameRegistrationPlugin::notifyRemovingResources(ResourceKey K) {<br>
 void EHFrameRegistrationPlugin::notifyTransferringResources(<br>
     ResourceKey DstKey, ResourceKey SrcKey) {<br>
   auto SI = EHFrameRanges.find(SrcKey);<br>
-  if (SI != EHFrameRanges.end()) {<br>
+  if (SI == EHFrameRanges.end())<br>
+    return;<br>
+<br>
+  auto DI = EHFrameRanges.find(DstKey);<br>
+  if (DI != EHFrameRanges.end()) {<br>
     auto &SrcRanges = SI->second;<br>
-    auto &DstRanges = EHFrameRanges[DstKey];<br>
+    auto &DstRanges = DI->second;<br>
     DstRanges.reserve(DstRanges.size() + SrcRanges.size());<br>
     for (auto &SrcRange : SrcRanges)<br>
       DstRanges.push_back(std::move(SrcRange));<br>
     EHFrameRanges.erase(SI);<br>
+  } else {<br>
+    // We need to move SrcKey's ranges over without invalidating the SI<br>
+    // iterator.<br>
+    auto Tmp = std::move(SI->second);<br>
+    EHFrameRanges.erase(SI);<br>
+    EHFrameRanges[DstKey] = std::move(Tmp);<br>
   }<br>
 }<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>
</blockquote></div>