Skip to content

Commit 9b9f1f9

Browse files
authored
Merge pull request swiftlang#31268 from eeckstein/fix-trvopt-5.3
[5.3] TempRValueOpt: fix a compile time crash in tryOptimizeStoreIntoTemp
2 parents b130ece + 08f9eee commit 9b9f1f9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/SILOptimizer/Transforms/TempRValueElimination.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,16 @@ TempRValueOptPass::tryOptimizeStoreIntoTemp(StoreInst *si) {
604604
// We pass in SILValue() since we do not have a source address.
605605
if (!collectLoads(useOper, user, tempObj, SILValue(), loadInsts))
606606
return {std::next(si->getIterator()), false};
607+
608+
// Bail if there is any kind of user which is not handled in the code below.
609+
switch (user->getKind()) {
610+
case SILInstructionKind::CopyAddrInst:
611+
case SILInstructionKind::FixLifetimeInst:
612+
case SILInstructionKind::MarkDependenceInst:
613+
continue;
614+
default:
615+
return {std::next(si->getIterator()), false};
616+
}
607617
}
608618

609619
// Since store is always a consuming operation, we do not need to worry about

test/SILOptimizer/temp_rvalue_opt_ossa.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,22 @@ bb0(%0 : $*Klass):
11591159
%9999 = tuple()
11601160
return %9999 : $()
11611161
}
1162+
1163+
// Check that we don't crash with this.
1164+
// CHECK-LABEL: sil [ossa] @unhandled_user : $@convention(thin) (@owned Klass) -> @owned Klass {
1165+
// CHECK: alloc_stack
1166+
// CHECK: store
1167+
// CHECK: begin_access
1168+
// CHECK: load
1169+
// CHECK: } // end sil function 'unhandled_user'
1170+
sil [ossa] @unhandled_user : $@convention(thin) (@owned Klass) -> @owned Klass {
1171+
bb0(%0 : @owned $Klass):
1172+
%5 = alloc_stack $Klass
1173+
store %0 to [init] %5 : $*Klass
1174+
%104 = begin_access [read] [static] %5 : $*Klass
1175+
%105 = load [take] %104 : $*Klass
1176+
end_access %104 : $*Klass
1177+
dealloc_stack %5 : $*Klass
1178+
return %105 : $Klass
1179+
}
1180+

0 commit comments

Comments
 (0)