From b83e788db5c2e0bf5c751536d17723626e9a4b68 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 24 Mar 2014 00:47:18 +0000 Subject: InstrProf: Silence spurious warnings in GCC 4.8 No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204580 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ProfileData/InstrProfReader.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib/ProfileData') diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index 47853ad8b7..b07f402777 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -118,11 +118,12 @@ uint64_t getRawMagic() { template bool RawInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) { - if (DataBuffer.getBufferSize() < sizeof(getRawMagic())) + if (DataBuffer.getBufferSize() < sizeof(uint64_t)) return false; - const RawHeader *Header = (const RawHeader *)DataBuffer.getBufferStart(); - return getRawMagic() == Header->Magic || - sys::SwapByteOrder(getRawMagic()) == Header->Magic; + uint64_t Magic = + *reinterpret_cast(DataBuffer.getBufferStart()); + return getRawMagic() == Magic || + sys::SwapByteOrder(getRawMagic()) == Magic; } template @@ -131,7 +132,8 @@ error_code RawInstrProfReader::readHeader() { return error(instrprof_error::bad_magic); if (DataBuffer->getBufferSize() < sizeof(RawHeader)) return error(instrprof_error::bad_header); - const RawHeader *Header = (const RawHeader *)DataBuffer->getBufferStart(); + auto *Header = + reinterpret_cast(DataBuffer->getBufferStart()); ShouldSwapBytes = Header->Magic != getRawMagic(); return readHeader(*Header); } @@ -159,10 +161,11 @@ error_code RawInstrProfReader::readHeader(const RawHeader &Header) { if (FileSize != DataBuffer->getBufferSize()) return error(instrprof_error::bad_header); - Data = (ProfileData *)(DataBuffer->getBufferStart() + DataOffset); + const char *Start = DataBuffer->getBufferStart(); + Data = reinterpret_cast(Start + DataOffset); DataEnd = Data + DataSize; - CountersStart = (uint64_t *)(DataBuffer->getBufferStart() + CountersOffset); - NamesStart = DataBuffer->getBufferStart() + NamesOffset; + CountersStart = reinterpret_cast(Start + CountersOffset); + NamesStart = Start + NamesOffset; return success(); } @@ -179,10 +182,11 @@ RawInstrProfReader::readNextRecord(InstrProfRecord &Record) { swap(Data->NumCounters)); // Check bounds. + auto *NamesStartAsCounter = reinterpret_cast(NamesStart); if (RawName.data() < NamesStart || RawName.data() + RawName.size() > DataBuffer->getBufferEnd() || RawCounts.data() < CountersStart || - RawCounts.data() + RawCounts.size() > (uint64_t *)NamesStart) + RawCounts.data() + RawCounts.size() > NamesStartAsCounter) return error(instrprof_error::malformed); // Store the data in Record, byte-swapping as necessary. -- cgit v1.2.3