[llvm] 91434d4 - [JITLink] Fix element-present check in MachOLinkGraphParser.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 26 20:48:46 PDT 2021


Author: Lang Hames
Date: 2021-10-26T20:48:40-07:00
New Revision: 91434d44699642075378c888bf61715ff2d9e23f

URL: https://github.com/llvm/llvm-project/commit/91434d44699642075378c888bf61715ff2d9e23f
DIFF: https://github.com/llvm/llvm-project/commit/91434d44699642075378c888bf61715ff2d9e23f.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h
index 4c82768f9fdb..d6ea4e2c244c 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<NormalizedSymbol &> findSymbolByIndex(uint64_t Index) {
-    if (Index >= IndexToSymbol.size())
-      return make_error<JITLinkError>("Symbol index out of range");
-    auto *Sym = IndexToSymbol[Index];
-    if (!Sym)
+    auto I = IndexToSymbol.find(Index);
+    if (I == IndexToSymbol.end())
       return make_error<JITLinkError>("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


        


More information about the llvm-commits mailing list