<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jun 6, 2013, at 4:33 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Thu, Jun 6, 2013 at 4:23 PM, Arnold Schwaighofer<br><<a href="mailto:aschwaighofer@apple.com">aschwaighofer@apple.com</a>> wrote:<br><blockquote type="cite">Author: arnolds<br>Date: Thu Jun  6 18:23:14 2013<br>New Revision: 183459<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=183459&view=rev">http://llvm.org/viewvc/llvm-project?rev=183459&view=rev</a><br>Log:<br>CodeGenSchedule: smallvector.push_back(smallvector[0]) is dangerous<br><br>The element passed to push_back is not copied before the vector reallocates.<br></blockquote><br>A similar change to this has been previously reverted: r178319<br><br>We should probably fix SmallVector to allow this, consistent with<br>standard containers, to avoid this pitfall now & in the future.<br></div></blockquote><div dir="auto"><br></div><div dir="auto">Agreed.</div><div dir="auto"><br></div><div dir="auto">Meanwhile I think the proper workaround is:</div><div dir="auto"><br></div><div dir="auto">RWSequences.reserve(RWSequences.size()+1);</div><div dir="auto">RWSequences.push_back(RWSequences[OperIdx]);</div><div><br></div><div>...rather than copying the vector. Anyone disagree?</div><div><br></div><div>-Andy</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite">The client needs to copy the element first before passing it to push_back.<br><br>No test case, will be tested by follow-up swift scheduler model change (it<br>segfaults without this change).<br><br>Modified:<br>   llvm/trunk/utils/TableGen/CodeGenSchedule.cpp<br><br>Modified: llvm/trunk/utils/TableGen/CodeGenSchedule.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenSchedule.cpp?rev=183459&r1=183458&r2=183459&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenSchedule.cpp?rev=183459&r1=183458&r2=183459&view=diff</a><br>==============================================================================<br>--- llvm/trunk/utils/TableGen/CodeGenSchedule.cpp (original)<br>+++ llvm/trunk/utils/TableGen/CodeGenSchedule.cpp Thu Jun  6 18:23:14 2013<br>@@ -1172,7 +1172,9 @@ pushVariant(const TransVariant &VInfo, b<br>    unsigned OperIdx = RWSequences.size()-1;<br>    // Make N-1 copies of this transition's last sequence.<br>    for (unsigned i = 1, e = SelectedRWs.size(); i != e; ++i) {<br>-      RWSequences.push_back(RWSequences[OperIdx]);<br>+      // Create a temporary copy the vector could reallocate.<br>+      SmallVector<unsigned, 4> Tmp = RWSequences[OperIdx];<br>+      RWSequences.push_back(Tmp);<br>    }<br>    // Push each of the N elements of the SelectedRWs onto a copy of the last<br>    // sequence (split the current operand into N operands).<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br></body></html>