Skip to content

Commit b1db77a

Browse files
authored
Fix ConnectionGraph verification for calls to no return functions. (#33655)
Functions that do not have a return, and instead end with 'unreachable' due to NoReturnFolding will not have a ReturnNode in the connection graph. A caller calling a no return function then may not have a CGNode corresponding to the call's result. Fix the ConnectionGraph's verifier so we don't assert in such cases.
1 parent 82fc202 commit b1db77a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,13 @@ void EscapeAnalysis::ConnectionGraph::verify() const {
16231623
if (auto ai = dyn_cast<ApplyInst>(&i)) {
16241624
if (EA->canOptimizeArrayUninitializedCall(ai).isValid())
16251625
continue;
1626+
// Ignore checking CGNode mapping for result of apply to a no return
1627+
// function that will have a null ReturnNode
1628+
if (auto *callee = ai->getReferencedFunctionOrNull()) {
1629+
if (EA->getFunctionInfo(callee)->isValid())
1630+
if (!EA->getConnectionGraph(callee)->getReturnNodeOrNull())
1631+
continue;
1632+
}
16261633
}
16271634
for (auto result : i.getResults()) {
16281635
if (EA->getPointerBase(result))

test/SILOptimizer/escape_analysis.sil

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,3 +1983,27 @@ bb4:
19831983
%z = tuple ()
19841984
return %z : $()
19851985
}
1986+
1987+
// Test CGNode mapping for result of an apply to no return function
1988+
// CHECK-LABEL:CG of $testcaller
1989+
// CHECK: Arg [ref] %0 Esc: A, Succ: (%0.1)
1990+
// CHECK: Con [int] %0.1 Esc: A, Succ: (%0.2)
1991+
// CHECK: Con [ref] %0.2 Esc: A, Succ:
1992+
// CHECK-LABEL:End
1993+
sil hidden [noinline] @$testcaller : $@convention(thin) (@owned Z) -> () {
1994+
bb0(%0 : $Z):
1995+
%2 = function_ref @$noreturncallee : $@convention(thin) (@guaranteed Z) -> @owned Z
1996+
%3 = apply %2(%0) : $@convention(thin) (@guaranteed Z) -> @owned Z
1997+
dealloc_ref %3 : $Z
1998+
%5 = tuple ()
1999+
return %5 : $()
2000+
}
2001+
2002+
// CHECK-LABEL:CG of $noreturncallee
2003+
// CHECK: Arg [ref] %0 Esc: A, Succ:
2004+
// CHECK-LABEL:End
2005+
sil hidden [noinline] @$noreturncallee : $@convention(thin) (@guaranteed Z) -> @owned Z {
2006+
bb0(%0 : $Z):
2007+
unreachable
2008+
}
2009+

0 commit comments

Comments
 (0)