[SEH] Deal with users of the old lpad for SEH catch-all blocks
[oota-llvm.git] / lib / CodeGen / WinEHPrepare.cpp
index afe26ff8224a9b87487a34e209e51f9ba20cfb65..4b0ce21111b2048d388b3dbbb410ac58c5d4bfdc 100644 (file)
@@ -433,6 +433,10 @@ bool WinEHPrepare::prepareExceptionHandlers(
       Invoke->setUnwindDest(NewLPadBB);
     }
 
+    // If anyone is still using the old landingpad value, just give them undef
+    // instead. The eh pointer and selector values are not real.
+    LPad->replaceAllUsesWith(UndefValue::get(LPad->getType()));
+
     // Replace the mapping of any nested landing pad that previously mapped
     // to this landing pad with a referenced to the cloned version.
     for (auto &LPadPair : NestedLPtoOriginalLP) {
@@ -636,6 +640,11 @@ void WinEHPrepare::promoteLandingPadValues(LandingPadInst *LPad) {
     PromoteMemToReg(EHAllocas, *DT);
     EHAllocas.clear();
   }
+
+  // After promotion, some extracts may be trivially dead. Remove them.
+  SmallVector<Value *, 4> Users(LPad->user_begin(), LPad->user_end());
+  for (auto *U : Users)
+    RecursivelyDeleteTriviallyDeadInstructions(U);
 }
 
 void WinEHPrepare::completeNestedLandingPad(Function *ParentFn,