Extracted from D25313, as suggested by Justin Bogner.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284220
91177308-0d34-0410-b5e6-
96231b3b80d8
inline SDValue::SDValue(SDNode *node, unsigned resno)
: Node(node), ResNo(resno) {
- assert((!Node || ResNo < Node->getNumValues()) &&
+ // Explicitly check for !ResNo to avoid use-after-free, because there are
+ // callers that use SDValue(N, 0) with a deleted N to indicate successful
+ // combines.
+ assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
"Invalid result number for the given node!");
assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
}
SDValue Op1 = Node->getOperand(1);
SDValue combined;
for (SDNode::use_iterator UI = Op0.getNode()->use_begin(),
- UE = Op0.getNode()->use_end(); UI != UE; ++UI) {
- SDNode *User = *UI;
+ UE = Op0.getNode()->use_end(); UI != UE;) {
+ SDNode *User = *UI++;
if (User == Node || User->use_empty())
continue;
// Convert the other matching node(s), too;