For landingpads with {} type, SCCP ended up dropping them, because
we considered them as safe to remove.
bool Instruction::isSafeToRemove() const {
return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
- !this->isTerminator();
+ !this->isTerminator() && !this->isEHPad();
}
bool Instruction::willReturn() const {
--- /dev/null
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -ipsccp < %s | FileCheck %s
+
+; SCCP should never remove landingpads.
+
+declare void @fn()
+
+define void @test() personality i8* null {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: invoke void @fn()
+; CHECK-NEXT: to label [[SUCCESS:%.*]] unwind label [[FAILURE:%.*]]
+; CHECK: success:
+; CHECK-NEXT: ret void
+; CHECK: failure:
+; CHECK-NEXT: [[PAD:%.*]] = landingpad {}
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: unreachable
+;
+ invoke void @fn()
+ to label %success unwind label %failure
+
+success:
+ ret void
+
+failure:
+ %pad = landingpad {}
+ cleanup
+ unreachable
+}