Skip to content

Commit 434d247

Browse files
authored
Merge pull request swiftlang#27778 from gottesmm/pr-7240e28720796b293ae617197f2683b512fdfdd7
[mandatory-inlining] Make cleanupLoadedCalleeValue more conservative.
2 parents ccb66d1 + 95afa84 commit 434d247

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,12 @@ static void fixupReferenceCounts(
253253
}
254254

255255
static SILValue cleanupLoadedCalleeValue(SILValue calleeValue, LoadInst *li) {
256-
auto *pbi = cast<ProjectBoxInst>(li->getOperand());
257-
auto *abi = cast<AllocBoxInst>(pbi->getOperand());
256+
auto *pbi = dyn_cast<ProjectBoxInst>(li->getOperand());
257+
if (!pbi)
258+
return SILValue();
259+
auto *abi = dyn_cast<AllocBoxInst>(pbi->getOperand());
260+
if (!abi)
261+
return SILValue();
258262

259263
// The load instruction must have no more uses or a single destroy left to
260264
// erase it.

test/SILOptimizer/mandatory_inlining.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,3 +1401,30 @@ bb6:
14011401
%tuple = tuple()
14021402
return %tuple : $()
14031403
}
1404+
1405+
sil [transparent] @escaping_thunk : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
1406+
bb0(%1 : $@callee_guaranteed () -> ()):
1407+
%9999 = tuple()
1408+
return %9999 : $()
1409+
}
1410+
1411+
// Make sure that we do not crash here.
1412+
//
1413+
// CHECK-LABEL: sil @partial_apply_stack_failure : $@convention(thin) (@callee_guaranteed () -> ()) -> () {
1414+
// CHECK: } // end sil function 'partial_apply_stack_failure'
1415+
sil @partial_apply_stack_failure : $@convention(thin) (@callee_guaranteed () -> ()) -> () {
1416+
bb0(%0 : $@callee_guaranteed () -> ()):
1417+
%1 = alloc_stack $@callee_guaranteed () -> ()
1418+
store %0 to %1 : $*@callee_guaranteed () -> ()
1419+
%2 = load %1 : $*@callee_guaranteed () -> ()
1420+
strong_retain %2 : $@callee_guaranteed () -> ()
1421+
%thunk = function_ref @escaping_thunk : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
1422+
%2a = partial_apply [callee_guaranteed] [on_stack] %thunk(%2) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
1423+
%2b = mark_dependence %2a : $@noescape @callee_guaranteed () -> () on %2 : $@callee_guaranteed () -> ()
1424+
apply %2b() : $@noescape @callee_guaranteed () -> ()
1425+
dealloc_stack %2a : $@noescape @callee_guaranteed () -> ()
1426+
destroy_addr %1 : $*@callee_guaranteed () -> ()
1427+
dealloc_stack %1 : $*@callee_guaranteed () -> ()
1428+
%9999 = tuple()
1429+
return %9999 : $()
1430+
}

0 commit comments

Comments
 (0)