diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -30,6 +30,7 @@ #include "bolt/Utils/CommandLineOpts.h" #include "bolt/Utils/Utils.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" @@ -2424,8 +2425,8 @@ Address, /*CheckPastEnd*/ true, /*UseMaxSize*/ IsAArch64); if (!IsSectionRelocation) { - if (BinaryFunction *BF = - BC->getBinaryFunctionContainingAddress(SymbolAddress)) { + BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(SymbolAddress); + if (BF) { if (BF != ReferencedBF) { // It's possible we are referencing a function without referencing any // code, e.g. when taking a bitmask action on a function address. @@ -2452,20 +2453,16 @@ // if a non-pc-relative relocation in the code is pointing to (fptr - 1). if (IsToCode && ContainingBF && !Relocation::isPCRelative(RType) && (!ReferencedBF || (ReferencedBF->getAddress() != Address))) { - if (const BinaryFunction *RogueBF = - BC->getBinaryFunctionAtAddress(Address + 1)) { + const BinaryFunction *RogueBF = BC->getBinaryFunctionAtAddress(Address + 1); + if (RogueBF) { // Do an extra check that the function was referenced previously. // It's a linear search, but it should rarely happen. - bool Found = false; - for (const auto &RelKV : ContainingBF->Relocations) { - const Relocation &Rel = RelKV.second; - if (Rel.Symbol == RogueBF->getSymbol() && - !Relocation::isPCRelative(Rel.Type)) { - Found = true; - break; - } - } - + auto CheckReloc = [&](const Relocation &Rel) { + return Rel.Symbol == RogueBF->getSymbol() && + !Relocation::isPCRelative(Rel.Type); + }; + bool Found = llvm::any_of( + llvm::make_second_range(ContainingBF->Relocations), CheckReloc); if (Found) { errs() << "BOLT-WARNING: detected possible compiler de-virtualization " "bug: -1 addend used with non-pc-relative relocation against " @@ -2601,9 +2598,9 @@ LLVM_DEBUG({ dbgs() << "BOLT-DEBUG: processing ending on data relocation " << NumDataRelocations << ": "; + printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress, + Addend, ExtractedValue); }); - printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress, - Addend, ExtractedValue); } return (!opts::MaxDataRelocations ||