@@ -91,12 +91,14 @@ static Error initializeReader(InstrProfReader &Reader) {
9191// / associated endian format to read the binary ids correctly.
9292static Error
9393readBinaryIdsInternal (const MemoryBuffer &DataBuffer,
94- const uint64_t BinaryIdsSize,
95- const uint8_t *BinaryIdsStart,
94+ ArrayRef<uint8_t > BinaryIdsBuffer,
9695 std::vector<llvm::object::BuildID> &BinaryIds,
9796 const llvm::endianness Endian) {
9897 using namespace support ;
9998
99+ const uint64_t BinaryIdsSize = BinaryIdsBuffer.size ();
100+ const uint8_t *BinaryIdsStart = BinaryIdsBuffer.data ();
101+
100102 if (BinaryIdsSize == 0 )
101103 return Error::success ();
102104
@@ -584,10 +586,10 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
584586 const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd ();
585587 if (BinaryIdSize % sizeof (uint64_t ) || BinaryIdEnd > BufferEnd)
586588 return error (instrprof_error::bad_header);
587- if (BinaryIdSize != 0 ) {
588- if (Error Err =
589- readBinaryIdsInternal (*DataBuffer, BinaryIdSize, BinaryIdStart ,
590- BinaryIds, getDataEndianness ()))
589+ ArrayRef< uint8_t > BinaryIdsBuffer (BinaryIdStart, BinaryIdSize);
590+ if (!BinaryIdsBuffer. empty ()) {
591+ if (Error Err = readBinaryIdsInternal (*DataBuffer, BinaryIdsBuffer ,
592+ BinaryIds, getDataEndianness ()))
591593 return Err;
592594 }
593595
@@ -1383,13 +1385,13 @@ Error IndexedInstrProfReader::readHeader() {
13831385 if (Header->getIndexedProfileVersion () >= 9 ) {
13841386 const unsigned char *Ptr = Start + Header->BinaryIdOffset ;
13851387 // Read binary ids size.
1386- BinaryIdsSize =
1388+ uint64_t BinaryIdsSize =
13871389 support::endian::readNext<uint64_t , llvm::endianness::little>(Ptr);
13881390 if (BinaryIdsSize % sizeof (uint64_t ))
13891391 return error (instrprof_error::bad_header);
13901392 // Set the binary ids start.
1391- BinaryIdsStart = Ptr;
1392- if (BinaryIdsStart > (const unsigned char *)DataBuffer->getBufferEnd ())
1393+ BinaryIdsBuffer = ArrayRef< uint8_t >( Ptr, BinaryIdsSize) ;
1394+ if (Ptr > (const unsigned char *)DataBuffer->getBufferEnd ())
13931395 return make_error<InstrProfError>(instrprof_error::malformed,
13941396 " corrupted binary ids" );
13951397 }
@@ -1691,8 +1693,8 @@ Error IndexedInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {
16911693
16921694Error IndexedInstrProfReader::readBinaryIds (
16931695 std::vector<llvm::object::BuildID> &BinaryIds) {
1694- return readBinaryIdsInternal (*DataBuffer, BinaryIdsSize, BinaryIdsStart ,
1695- BinaryIds, llvm::endianness::little);
1696+ return readBinaryIdsInternal (*DataBuffer, BinaryIdsBuffer, BinaryIds ,
1697+ llvm::endianness::little);
16961698}
16971699
16981700Error IndexedInstrProfReader::printBinaryIds (raw_ostream &OS) {
0 commit comments