Skip to content

Commit 8cd04c2

Browse files
authored
Merge pull request #72490 from eeckstein/fix-predictable-deadalloc-elim
PredictableMemOpt: fix a crash, caused by a wrong instruction cast
2 parents 0edd96e + 16b59db commit 8cd04c2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,9 @@ bool AllocOptimize::tryToRemoveDeadAllocation() {
25702570
// Today if we promote, this is always a store, since we would have
25712571
// blown up the copy_addr otherwise. Given that, always make sure we
25722572
// clean up the src as appropriate after we optimize.
2573-
auto *si = cast<StoreInst>(pmoMemUse.Inst);
2573+
auto *si = dyn_cast<StoreInst>(pmoMemUse.Inst);
2574+
if (!si)
2575+
return false;
25742576
auto src = si->getSrc();
25752577

25762578
// Bail if src has any uses that are forwarding unowned uses. This

test/SILOptimizer/predictable_deadalloc_elim_ownership.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ case none
2121
case some(T)
2222
}
2323

24+
protocol P {}
25+
struct S: P {}
26+
2427
///////////
2528
// Tests //
2629
///////////
@@ -749,3 +752,13 @@ bb6:
749752
unreachable
750753
}
751754

755+
// CHECK-LABEL: sil [ossa] @testStoredOnlyExistential :
756+
// CHECK: alloc_stack
757+
// CHECK: } // end sil function 'testStoredOnlyExistential'
758+
sil [ossa] @testStoredOnlyExistential : $@convention(thin) (S) -> () {
759+
bb0(%0 : $S):
760+
%1 = alloc_stack $any P
761+
%4 = init_existential_addr %1 : $*any P, $S
762+
store %0 to [trivial] %4 : $*S
763+
unreachable
764+
}

0 commit comments

Comments
 (0)