Skip to content

Commit 7887912

Browse files
committed
[OpaqueValues] Pass direct to willThrowTyped.
The runtime function `swift_willThrowTyped` takes its argument `@in_guaranteed`. In opaque values SIL, that's passed directly. Don't store non-address errors before passing them to the function.
1 parent e6a34e8 commit 7887912

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/SILGen/SILGenStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
15911591
}, LookUpConformanceInModule(getModule().getSwiftModule()));
15921592

15931593
// Generic errors are passed indirectly.
1594-
if (!exnMV.getType().isAddress()) {
1594+
if (!exnMV.getType().isAddress() && useLoweredAddresses()) {
15951595
// Materialize the error so we can pass the address down to the
15961596
// swift_willThrowTyped.
15971597
exnMV = exnMV.materialize(*this, loc);

test/SILGen/opaque_values_silgen.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,3 +874,14 @@ struct Twople<T> {
874874
self.storage = (t1, t2)
875875
}
876876
}
877+
878+
// CHECK-LABEL: sil{{.*}} [ossa] @throwTypedValue : {{.*}} {
879+
// CHECK: bb0([[E:%[^,]+]] :
880+
// CHECK: [[SWIFT_WILL_THROW_TYPED:%[^,]+]] = function_ref @swift_willThrowTyped
881+
// CHECK: apply [[SWIFT_WILL_THROW_TYPED]]<Err>([[E]])
882+
// CHECK: throw [[E]]
883+
// CHECK-LABEL: } // end sil function 'throwTypedValue'
884+
@_silgen_name("throwTypedValue")
885+
func throwTypedValue(_ e: Err) throws(Err) { throw e }
886+
887+
struct Err : Error {}

0 commit comments

Comments
 (0)