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
This commit is contained in:
Duncan P. N. Exon Smith 2014-03-24 00:47:18 +00:00
parent 12da52f917
commit b83e788db5

View File

@ -118,11 +118,12 @@ uint64_t getRawMagic<uint32_t>() {
template <class IntPtrT>
bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
if (DataBuffer.getBufferSize() < sizeof(getRawMagic<IntPtrT>()))
if (DataBuffer.getBufferSize() < sizeof(uint64_t))
return false;
const RawHeader *Header = (const RawHeader *)DataBuffer.getBufferStart();
return getRawMagic<IntPtrT>() == Header->Magic ||
sys::SwapByteOrder(getRawMagic<IntPtrT>()) == Header->Magic;
uint64_t Magic =
*reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
return getRawMagic<IntPtrT>() == Magic ||
sys::SwapByteOrder(getRawMagic<IntPtrT>()) == Magic;
}
template <class IntPtrT>
@ -131,7 +132,8 @@ error_code RawInstrProfReader<IntPtrT>::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<const RawHeader *>(DataBuffer->getBufferStart());
ShouldSwapBytes = Header->Magic != getRawMagic<IntPtrT>();
return readHeader(*Header);
}
@ -159,10 +161,11 @@ error_code RawInstrProfReader<IntPtrT>::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<const ProfileData *>(Start + DataOffset);
DataEnd = Data + DataSize;
CountersStart = (uint64_t *)(DataBuffer->getBufferStart() + CountersOffset);
NamesStart = DataBuffer->getBufferStart() + NamesOffset;
CountersStart = reinterpret_cast<const uint64_t *>(Start + CountersOffset);
NamesStart = Start + NamesOffset;
return success();
}
@ -179,10 +182,11 @@ RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
swap(Data->NumCounters));
// Check bounds.
auto *NamesStartAsCounter = reinterpret_cast<const uint64_t *>(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.