diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -481,7 +481,7 @@ /// to function \p BF. std::string generateJumpTableName(const BinaryFunction &BF, uint64_t Address); - /// Free meory used by jump table offsets + /// Free memory used by jump table offsets void clearJumpTableOffsets() { for (auto& JTI: JumpTables) { JumpTable& JT = *JTI.second; diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -761,19 +761,21 @@ const MCSymbol * BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address, JumpTable::JumpTableType Type) { + auto isFragmentOf = [](BinaryFunction *Fragment, BinaryFunction *Parent) { + return (Fragment->isFragment() && Fragment->isParentFragment(Parent)); + }; + if (JumpTable *JT = getJumpTableContainingAddress(Address)) { assert(JT->Type == Type && "jump table types have to match"); - assert((JT->Parent == &Function || - (JT->Parent->isFragment() && - JT->Parent->isParentFragment(&Function)) || - (Function.isFragment() && Function.isParentFragment(JT->Parent))) && + assert((JT->Parent == &Function || isFragmentOf(JT->Parent, &Function) || + isFragmentOf(&Function, JT->Parent)) && "cannot re-use jump table of a different function"); assert(Address == JT->getAddress() && "unexpected non-empty jump table"); // Flush OffsetEntries with INVALID_OFFSET if multiple parents // Duplicate the entry for the parent function for easy access - if ((JT->Parent->isFragment() && JT->Parent->isParentFragment(&Function)) || - (Function.isFragment() && Function.isParentFragment(JT->Parent))) { + if (isFragmentOf(JT->Parent, &Function) || + isFragmentOf(&Function, JT->Parent)) { constexpr uint64_t INVALID_OFFSET = std::numeric_limits::max(); for (unsigned I = 0; I < JT->OffsetEntries.size(); ++I) JT->OffsetEntries[I] = INVALID_OFFSET; diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1756,12 +1756,6 @@ } clearList(JTSites); - // Free memory used by jump table offsets. - // for (auto &JTI : JumpTables) { - // JumpTable &JT = *JTI.second; - // clearList(JT.OffsetEntries); - // } - // Conservatively populate all possible destinations for unknown indirect // branches. if (opts::StrictMode && hasInternalReference()) {