diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -12029,7 +12029,11 @@ auto I = SDEI.find(From); if (I == SDEI.end()) return; - SDEI[To] = I->second; + + // Use of operator[] on the DenseMap may cause an insertion, which invalidates + // the iterator, hence the need to make a copy to prevent a use-after-free. + NodeExtraInfo Copy = I->second; + SDEI[To] = std::move(Copy); } #ifndef NDEBUG