diff options
author | Xinliang David Li <davidxl@google.com> | 2015-11-11 19:31:53 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-11-11 19:31:53 +0000 |
commit | 4d1bef3f76899db7ab48ddff8ae6c5f76db3ee80 (patch) | |
tree | 3ea3acb445a8f185f513bf3ffb41f93384b68c33 | |
parent | 0b44dcc44a0dec69c4e048ff8db42c4f7f905f64 (diff) | |
download | bcm5719-llvm-4d1bef3f76899db7ab48ddff8ae6c5f76db3ee80.tar.gz bcm5719-llvm-4d1bef3f76899db7ab48ddff8ae6c5f76db3ee80.zip |
Refactoring and fix another instance of asan error
llvm-svn: 252783
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 4f7328279e2..ddd23014673 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -244,12 +244,17 @@ void ValueProfData::deserializeTo(InstrProfRecord &Record, } } +static ValueProfData *AllocValueProfData(uint32_t TotalSize) { + void *RawMem = ::operator new(TotalSize); + ValueProfData *VPDMem = new (RawMem) ValueProfData(); + return VPDMem; +} + std::unique_ptr<ValueProfData> ValueProfData::serializeFrom(const InstrProfRecord &Record) { uint32_t TotalSize = getSize(Record); - void *RawMem = ::operator new(TotalSize); - ValueProfData *VPDMem = new (RawMem) ValueProfData(); - std::unique_ptr<ValueProfData> VPD(VPDMem); + + std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize)); VPD->TotalSize = TotalSize; VPD->NumValueKinds = Record.getNumValueKinds(); @@ -285,8 +290,8 @@ ValueProfData::getValueProfData(const unsigned char *D, if (TotalSize % sizeof(uint64_t)) return instrprof_error::malformed; - std::unique_ptr<ValueProfData> VPD( - reinterpret_cast<ValueProfData *>(new char[TotalSize])); + std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize)); + memcpy(VPD.get(), D, TotalSize); // Byte swap. VPD->swapBytesToHost(Endianness); |