From 9742c00778d9c96b7722058845c4b9bc098baef8 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 26 Oct 2021 18:32:06 -0700 Subject: [PATCH] [JITLink] Fix element-present check in MachOLinkGraphParser. Not all symbols are added to the index-to-symbol map, so we shouldn't use the size of the map as a proxy for the highest valid index. (cherry-picked from 91434d44699642075378c888bf61715ff2d9e23f) --- llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h index 90b14c44ff8a8d..33fa84821ceba3 100644 --- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h @@ -125,13 +125,12 @@ class MachOLinkGraphBuilder { /// given index is out of range, or if no symbol has been added for the given /// index. Expected findSymbolByIndex(uint64_t Index) { - if (Index >= IndexToSymbol.size()) - return make_error("Symbol index out of range"); - auto *Sym = IndexToSymbol[Index]; - if (!Sym) + auto I = IndexToSymbol.find(Index); + if (I == IndexToSymbol.end()) return make_error("No symbol at index " + formatv("{0:d}", Index)); - return *Sym; + assert(I->second && "Null symbol at index"); + return *I->second; } /// Returns the symbol with the highest address not greater than the search