[llvm] r204580 - InstrProf: Silence spurious warnings in GCC 4.8

Duncan P. N. Exon Smith dexonsmith at apple.com
Sun Mar 23 17:47:18 PDT 2014


Author: dexonsmith
Date: Sun Mar 23 19:47:18 2014
New Revision: 204580

URL: http://llvm.org/viewvc/llvm-project?rev=204580&view=rev
Log:
InstrProf: Silence spurious warnings in GCC 4.8

No functionality change.

Modified:
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=204580&r1=204579&r2=204580&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Sun Mar 23 19:47:18 2014
@@ -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>::
     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>::
   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>::readNextRec
                                 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.





More information about the llvm-commits mailing list