Skip to content

Commit 3b8656c

Browse files
committed
Create phi argument for only non-empty direct result in epilog bb
1 parent f65dac9 commit 3b8656c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/SILGen/SILGenEpilog.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ void SILGenFunction::prepareEpilog(Optional<Type> directResultType,
2929
// Set NeedsReturn for indirect or direct results. This ensures that SILGen
3030
// emits unreachable if there is no source level return.
3131
NeedsReturn = !(*directResultType)->isEqual(TupleType::getEmpty(getASTContext()));
32-
for (auto directResult : fnConv.getDirectSILResults()) {
33-
SILType resultType = F.getLoweredType(F.mapTypeIntoContext(
34-
fnConv.getSILType(directResult, getTypeExpansionContext())));
35-
epilogBB->createPhiArgument(resultType, OwnershipKind::Owned);
32+
if (NeedsReturn) {
33+
for (auto directResult : fnConv.getDirectSILResults()) {
34+
SILType resultType = F.getLoweredType(F.mapTypeIntoContext(
35+
fnConv.getSILType(directResult, getTypeExpansionContext())));
36+
epilogBB->createPhiArgument(resultType, OwnershipKind::Owned);
37+
}
3638
}
3739
}
3840

test/SILGen/opaque_values_silgen.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,12 @@ func anon_read_only_capture(_ x: Int) -> Int {
375375
return ({ x })()
376376
}
377377

378+
379+
// CHECK-LABEL: sil private [ossa] @$s20opaque_values_silgen22testEmptyReturnClosureyyFyycyKXEfu_yycfU_ : $@convention(thin) @substituted <τ_0_0> () -> @out τ_0_0 for <()> {
380+
// CHECK-NOT: bb1
381+
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen22testEmptyReturnClosureyyFyycyKXEfu_yycfU_'
382+
func testEmptyReturnClosure() {
383+
func bar() {}
384+
let b = nil ?? { bar() }
385+
}
386+

0 commit comments

Comments
 (0)