[llvm] r252783 - Refactoring and fix another instance of asan error
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 11 11:49:58 PST 2015
On Wed, Nov 11, 2015 at 11:38 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Wed, Nov 11, 2015 at 11:31 AM, Xinliang David Li via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: davidxl
>> Date: Wed Nov 11 13:31:53 2015
>> New Revision: 252783
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=252783&view=rev
>> Log:
>> Refactoring and fix another instance of asan error
>>
>> Modified:
>> llvm/trunk/lib/ProfileData/InstrProf.cpp
>>
>> Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=252783&r1=252782&r2=252783&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
>> +++ llvm/trunk/lib/ProfileData/InstrProf.cpp Wed Nov 11 13:31:53 2015
>> @@ -244,12 +244,17 @@ void ValueProfData::deserializeTo(InstrP
>> }
>> }
>>
>> +static ValueProfData *AllocValueProfData(uint32_t TotalSize) {
>> + void *RawMem = ::operator new(TotalSize);
>> + ValueProfData *VPDMem = new (RawMem) ValueProfData();
>> + return VPDMem;
>> +}
>>
>
> Perhaps this utility should return unique_ptr? Since both the callers want
> one anyway? (& it ensures safety, etc from the source - rather than having
> a raw owned pointer crossing that call boundary)
>
We can do that. Probably leave it till the next cleanup.
thanks,
david
>
>> +
>> 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 un
>> 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);
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151111/afcdf55c/attachment-0001.html>
More information about the llvm-commits
mailing list