From 3bd2524b601c6c5de28d931705bf66ce2dd0fc4a Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Thu, 6 Jun 2013 23:23:14 +0000 Subject: [PATCH] CodeGenSchedule: smallvector.push_back(smallvector[0]) is dangerous The element passed to push_back is not copied before the vector reallocates. The client needs to copy the element first before passing it to push_back. No test case, will be tested by follow-up swift scheduler model change (it segfaults without this change). llvm-svn: 183459 --- llvm/utils/TableGen/CodeGenSchedule.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index f2af7edbb2ef..53b72d03b5b4 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -1172,7 +1172,9 @@ pushVariant(const TransVariant &VInfo, bool IsRead) { unsigned OperIdx = RWSequences.size()-1; // Make N-1 copies of this transition's last sequence. for (unsigned i = 1, e = SelectedRWs.size(); i != e; ++i) { - RWSequences.push_back(RWSequences[OperIdx]); + // Create a temporary copy the vector could reallocate. + SmallVector Tmp = RWSequences[OperIdx]; + RWSequences.push_back(Tmp); } // Push each of the N elements of the SelectedRWs onto a copy of the last // sequence (split the current operand into N operands).