From 1576d70a2379b7d27bed701e6807febf6ecd8ba9 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 12 Jun 2020 00:01:54 -0700 Subject: [PATCH] [llvm/Object] Reimplment basic_symbol_iterator in TapiFile Use indices into the Symbols vector instead of casting the objects in the vector and dereferencing std::vector::end(). This change is NFC modulo the Windows failure reported by llvm-clang-x86_64-expensive-checks-win. Differential revision: https://reviews.llvm.org/D81717 --- lib/Object/TapiFile.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Object/TapiFile.cpp b/lib/Object/TapiFile.cpp index c732a8edbe7..7a361990ba5 100644 --- a/lib/Object/TapiFile.cpp +++ b/lib/Object/TapiFile.cpp @@ -75,30 +75,28 @@ TapiFile::TapiFile(MemoryBufferRef Source, const InterfaceFile &interface, TapiFile::~TapiFile() = default; -void TapiFile::moveSymbolNext(DataRefImpl &DRI) const { - const auto *Sym = reinterpret_cast(DRI.p); - DRI.p = reinterpret_cast(++Sym); -} +void TapiFile::moveSymbolNext(DataRefImpl &DRI) const { DRI.d.a++; } Error TapiFile::printSymbolName(raw_ostream &OS, DataRefImpl DRI) const { - const auto *Sym = reinterpret_cast(DRI.p); - OS << Sym->Prefix << Sym->Name; + assert(DRI.d.a < Symbols.size() && "Attempt to access symbol out of bounds"); + const Symbol &Sym = Symbols[DRI.d.a]; + OS << Sym.Prefix << Sym.Name; return Error::success(); } Expected TapiFile::getSymbolFlags(DataRefImpl DRI) const { - const auto *Sym = reinterpret_cast(DRI.p); - return Sym->Flags; + assert(DRI.d.a < Symbols.size() && "Attempt to access symbol out of bounds"); + return Symbols[DRI.d.a].Flags; } basic_symbol_iterator TapiFile::symbol_begin() const { DataRefImpl DRI; - DRI.p = reinterpret_cast(&*Symbols.begin()); + DRI.d.a = 0; return BasicSymbolRef{DRI, this}; } basic_symbol_iterator TapiFile::symbol_end() const { DataRefImpl DRI; - DRI.p = reinterpret_cast(&*Symbols.end()); + DRI.d.a = Symbols.size(); return BasicSymbolRef{DRI, this}; }