[llvm-branch-commits] [llvm-branch] r293650 - Merging r293522:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 31 09:02:49 PST 2017
Author: hans
Date: Tue Jan 31 11:02:48 2017
New Revision: 293650
URL: http://llvm.org/viewvc/llvm-project?rev=293650&view=rev
Log:
Merging r293522:
------------------------------------------------------------------------
r293522 | bogner | 2017-01-30 10:29:46 -0800 (Mon, 30 Jan 2017) | 8 lines
SDAG: Update ChainNodesMatched during UpdateChains if a node is replaced
Previously, we would hit UB (or the ISD::DELETED_NODE assert) if we
happened to replace a node during UpdateChains, because it would be
left in the list we were iterating over. This nulls out the pointer
when that happens so that we can avoid the issue.
Fixes llvm.org/PR31710
------------------------------------------------------------------------
Added:
llvm/branches/release_40/test/CodeGen/SystemZ/pr31710.ll
- copied unchanged from r293522, llvm/trunk/test/CodeGen/SystemZ/pr31710.ll
Modified:
llvm/branches/release_40/ (props changed)
llvm/branches/release_40/include/llvm/CodeGen/SelectionDAGISel.h
llvm/branches/release_40/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Propchange: llvm/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 31 11:02:48 2017
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,291858-291859,291863,291875,291909,291918,291966,291968,291979,292133,292242,292254-292255,292280,292323,292444,292467,292516,292583,292625,292641,292651,292667,292711-292713,292758,293021,293025,293259,293291,293293
+/llvm/trunk:155241,291858-291859,291863,291875,291909,291918,291966,291968,291979,292133,292242,292254-292255,292280,292323,292444,292467,292516,292583,292625,292641,292651,292667,292711-292713,292758,293021,293025,293259,293291,293293,293522
Modified: llvm/branches/release_40/include/llvm/CodeGen/SelectionDAGISel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/include/llvm/CodeGen/SelectionDAGISel.h?rev=293650&r1=293649&r2=293650&view=diff
==============================================================================
--- llvm/branches/release_40/include/llvm/CodeGen/SelectionDAGISel.h (original)
+++ llvm/branches/release_40/include/llvm/CodeGen/SelectionDAGISel.h Tue Jan 31 11:02:48 2017
@@ -305,7 +305,7 @@ private:
std::vector<unsigned> OpcodeOffset;
void UpdateChains(SDNode *NodeToMatch, SDValue InputChain,
- const SmallVectorImpl<SDNode *> &ChainNodesMatched,
+ SmallVectorImpl<SDNode *> &ChainNodesMatched,
bool isMorphNodeTo);
};
Modified: llvm/branches/release_40/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=293650&r1=293649&r2=293650&view=diff
==============================================================================
--- llvm/branches/release_40/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/branches/release_40/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Tue Jan 31 11:02:48 2017
@@ -2248,7 +2248,7 @@ GetVBR(uint64_t Val, const unsigned char
/// to use the new results.
void SelectionDAGISel::UpdateChains(
SDNode *NodeToMatch, SDValue InputChain,
- const SmallVectorImpl<SDNode *> &ChainNodesMatched, bool isMorphNodeTo) {
+ SmallVectorImpl<SDNode *> &ChainNodesMatched, bool isMorphNodeTo) {
SmallVector<SDNode*, 4> NowDeadNodes;
// Now that all the normal results are replaced, we replace the chain and
@@ -2260,6 +2260,11 @@ void SelectionDAGISel::UpdateChains(
// Replace all the chain results with the final chain we ended up with.
for (unsigned i = 0, e = ChainNodesMatched.size(); i != e; ++i) {
SDNode *ChainNode = ChainNodesMatched[i];
+ // If ChainNode is null, it's because we replaced it on a previous
+ // iteration and we cleared it out of the map. Just skip it.
+ if (!ChainNode)
+ continue;
+
assert(ChainNode->getOpcode() != ISD::DELETED_NODE &&
"Deleted node left in chain");
@@ -2272,6 +2277,11 @@ void SelectionDAGISel::UpdateChains(
if (ChainVal.getValueType() == MVT::Glue)
ChainVal = ChainVal.getValue(ChainVal->getNumValues()-2);
assert(ChainVal.getValueType() == MVT::Other && "Not a chain?");
+ SelectionDAG::DAGNodeDeletedListener NDL(
+ *CurDAG, [&](SDNode *N, SDNode *E) {
+ std::replace(ChainNodesMatched.begin(), ChainNodesMatched.end(), N,
+ static_cast<SDNode *>(nullptr));
+ });
CurDAG->ReplaceAllUsesOfValueWith(ChainVal, InputChain);
// If the node became dead and we haven't already seen it, delete it.
More information about the llvm-branch-commits
mailing list