Skip to content

Commit 3760321

Browse files
authored
Merge pull request #69518 from slavapestov/fix-regression-typed-throws
SILGen: Fix crash when emitting throwing closure as opaque
2 parents 70a968a + 2f2ee61 commit 3760321

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/SILGen/SILGenProlog.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -1768,14 +1768,15 @@ static void emitIndirectErrorParameter(SILGenFunction &SGF,
17681768

17691769
// The calling convention always uses minimal resilience expansion.
17701770
auto errorConvType = SGF.SGM.Types.getLoweredType(
1771-
errorTypeInContext, TypeExpansionContext::minimal());
1771+
origErrorType, errorTypeInContext, TypeExpansionContext::minimal());
17721772

17731773
// And the abstraction pattern may force an indirect return even if the
17741774
// concrete type wouldn't normally be returned indirectly.
17751775
if (!SILModuleConventions::isThrownIndirectlyInSIL(errorConvType,
17761776
SGF.SGM.M)) {
17771777
if (!SILModuleConventions(SGF.SGM.M).useLoweredAddresses()
1778-
|| origErrorType.getErrorConvention(SGF.SGM.Types) != AbstractionPattern::Indirect)
1778+
|| origErrorType.getErrorConvention(SGF.SGM.Types)
1779+
!= AbstractionPattern::Indirect)
17791780
return;
17801781
}
17811782

@@ -1813,10 +1814,16 @@ uint16_t SILGenFunction::emitBasicProlog(
18131814

18141815
llvm::Optional<AbstractionPattern> origErrorType;
18151816
if (errorType) {
1816-
origErrorType = origClosureType
1817-
? origClosureType->getFunctionThrownErrorType()
1818-
: AbstractionPattern(genericSig.getCanonicalSignature(),
1819-
(*errorType)->getCanonicalType());
1817+
if (origClosureType &&
1818+
!origClosureType->isTypeParameterOrOpaqueArchetype()) {
1819+
origErrorType =
1820+
origClosureType->getFunctionThrownErrorType();
1821+
} else {
1822+
origErrorType =
1823+
AbstractionPattern(genericSig.getCanonicalSignature(),
1824+
(*errorType)->getCanonicalType());
1825+
}
1826+
18201827
emitIndirectErrorParameter(*this, *errorType, *origErrorType, DC);
18211828
}
18221829

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-emit-silgen -verify %s | %FileCheck %s
2+
3+
func callee<T>(_: T) {}
4+
5+
func g() throws {}
6+
7+
func caller() {
8+
callee { try g() }
9+
}
10+
11+
// CHECK-LABEL: sil private [ossa] @$s36literal_closure_reabstraction_throws6calleryyFyyKcfU_ : $@convention(thin) @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()> {
12+
// CHECK: bb0(%0 : $*()):
13+
// CHECK: debug_value undef : $any Error, var, name "$error", argno 1

0 commit comments

Comments
 (0)