<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 8, 2015 at 2:03 PM, Yaron Keren 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: yrnkrn<br>
Date: Sat Aug  8 16:03:19 2015<br>
New Revision: 244405<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=244405&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=244405&view=rev</a><br>
Log:<br>
Fix dangling reference in DwarfLinker.cpp. The original code<br>
<br>
  Seq.emplace_back(Seq.back());<br>
<br>
does not work as planned, since Seq.back() may become a dangling reference<br>
when emplace_back is called and possibly reallocates vector. To avoid this,<br>
the vector allocation should be reserved first and only then used.<br>
<br>
This broke test/tools/dsymutil/X86/custom-line-table.test with Visual C++ 2013.<br>
<br>
<br>
Modified:<br>
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>
<br>
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=244405&r1=244404&r2=244405&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=244405&r1=244404&r2=244405&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)<br>
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Sat Aug  8 16:03:19 2015<br>
@@ -2884,6 +2884,7 @@ void DwarfLinker::patchLineTableForUnit(<br>
       if (StopAddress != -1ULL && !Seq.empty()) {<br>
         // Insert end sequence row with the computed end address, but<br>
         // the same line as the previous one.<br>
+        Seq.reserve(Seq.size() + 1);<br>
         Seq.emplace_back(Seq.back());<br></blockquote><div><br>Might be less subtle to just write this as:<br><br>auto NextLine = Seq.back();<br>NextLine.Address = ...;<br>...<br>NextLine.EpilogueBegin = ...;<br>Seq.push_back(NextLine);<br><br>(alternatively: Seq.push_back(DWARFDebugLine::Row(Seq.back()); would also avoid the need for the reserve, but would still be bit non-obvious/subtle, like the reserve call is)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
         Seq.back().Address = StopAddress;<br>
         Seq.back().EndSequence = 1;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">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>