<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 11, 2015 at 11:49 AM, Xinliang David Li <span dir="ltr"><<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Nov 11, 2015 at 11:38 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 11, 2015 at 11:31 AM, Xinliang David Li via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: davidxl<br>
Date: Wed Nov 11 13:31:53 2015<br>
New Revision: 252783<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252783&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252783&view=rev</a><br>
Log:<br>
Refactoring and fix another instance of asan error<br>
<br>
Modified:<br>
llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
<br>
Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=252783&r1=252782&r2=252783&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=252783&r1=252782&r2=252783&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Wed Nov 11 13:31:53 2015<br>
@@ -244,12 +244,17 @@ void ValueProfData::deserializeTo(InstrP<br>
}<br>
}<br>
<br>
+static ValueProfData *AllocValueProfData(uint32_t TotalSize) {<br>
+ void *RawMem = ::operator new(TotalSize);<br>
+ ValueProfData *VPDMem = new (RawMem) ValueProfData();<br>
+ return VPDMem;<br>
+}<br></blockquote><div><br></div><div>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)</div></div></div></div></blockquote><div><br></div></span><div>We can do that. Probably leave it till the next cleanup.</div></div></div></div></blockquote><div><br></div><div>Actually easier/nicer if independent patches are committed independently, no need to wait to batch these things. So I just went ahead and committed the change in r252799.<br><br>Thanks,<br>- David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>thanks,</div><div><br></div><div>david</div><div><div class="h5"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
std::unique_ptr<ValueProfData><br>
ValueProfData::serializeFrom(const InstrProfRecord &Record) {<br>
uint32_t TotalSize = getSize(Record);<br>
- void *RawMem = ::operator new(TotalSize);<br>
- ValueProfData *VPDMem = new (RawMem) ValueProfData();<br>
- std::unique_ptr<ValueProfData> VPD(VPDMem);<br>
+<br>
+ std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize));<br>
<br>
VPD->TotalSize = TotalSize;<br>
VPD->NumValueKinds = Record.getNumValueKinds();<br>
@@ -285,8 +290,8 @@ ValueProfData::getValueProfData(const un<br>
if (TotalSize % sizeof(uint64_t))<br>
return instrprof_error::malformed;<br>
<br>
- std::unique_ptr<ValueProfData> VPD(<br>
- reinterpret_cast<ValueProfData *>(new char[TotalSize]));<br>
+ std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize));<br>
+<br>
memcpy(VPD.get(), D, TotalSize);<br>
// Byte swap.<br>
VPD->swapBytesToHost(Endianness);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>