Skip to content

Commit 489158c

Browse files
committed
Ensure that we don't add an indirect thrown error argument when unneeded
1 parent 927e242 commit 489158c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,8 @@ uint16_t SILGenFunction::emitBasicProlog(
18271827
(*errorType)->getCanonicalType());
18281828
}
18291829

1830-
if (origErrorType && errorType) {
1830+
if (origErrorType && errorType &&
1831+
F.getConventions().hasIndirectSILErrorResults()) {
18311832
emitIndirectErrorParameter(*this, *errorType, *origErrorType, DC);
18321833
}
18331834

test/SILGen/typed_throws_generic.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,20 @@ func reabstractClosureAsTypedThrowing(b: Bool) throws(MyError) -> Int {
237237
// CHECK: dealloc_stack [[INT_BOX]] : $*Int
238238
// CHECK-NEXT: throw [[ERROR]] : $MyError
239239
}
240+
241+
242+
extension Collection {
243+
func typedMap<T, E>(body: (Element) throws(E) -> T) throws(E) -> [T] {
244+
var result: [T] = []
245+
for element in self {
246+
result.append(try body(element))
247+
}
248+
return result
249+
}
250+
}
251+
252+
// CHECK-LABEL: sil private [ossa] @$s20typed_throws_generic9forcedMapySayq_GSayxGr0_lFq_xXEfU_ : $@convention(thin) <T, U> (@in_guaranteed T) -> (@out U, @error Never)
253+
func forcedMap<T, U>(_ source: [T]) -> [U] {
254+
// CHECK: bb0(%0 : $*U, %1 : $*T)
255+
return source.typedMap { $0 as! U }
256+
}

0 commit comments

Comments
 (0)