X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FProfileData%2FInstrProf.cpp;h=ef7b19b2882099b899a097de2fa15c4cfb48a958;hp=762f00b48b6404dfd272508a9b868af045261fa5;hb=4d60f67763b08c19335b29e96a61ad4cbce034d9;hpb=15d19608b087c452ba9d28bafa268426e7f6fab9 diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 762f00b48b6..ef7b19b2882 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -184,11 +184,13 @@ void ValueProfRecord::serializeFrom(const InstrProfRecord &Record, } } -template static T swapToHostOrder(T v, support::endianness Orig) { - if (Orig == getHostEndianness()) - return v; - sys::swapByteOrder(v); - return v; +template +static T swapToHostOrder(const unsigned char *&D, support::endianness Orig) { + using namespace support; + if (Orig == little) + return endian::readNext(D); + else + return endian::readNext(D); } // For writing/serializing, Old is the host endianness, and New is @@ -278,10 +280,9 @@ ValueProfData::getValueProfData(const unsigned char *D, if (D + sizeof(ValueProfData) > BufferEnd) return instrprof_error::truncated; - uint32_t TotalSize = swapToHostOrder( - reinterpret_cast(D)[0], Endianness); - uint32_t NumValueKinds = swapToHostOrder( - reinterpret_cast(D)[1], Endianness); + const unsigned char *Header = D; + uint32_t TotalSize = swapToHostOrder(Header, Endianness); + uint32_t NumValueKinds = swapToHostOrder(Header, Endianness); if (D + TotalSize > BufferEnd) return instrprof_error::too_large; @@ -307,7 +308,6 @@ ValueProfData::getValueProfData(const unsigned char *D, return instrprof_error::malformed; } - D += TotalSize; return std::move(VPD); }