Skip to content

Commit 8e1d25b

Browse files
committed
IRGen: Fix async throw emission for indirect direct values
rdar://76009728
1 parent 7d46760 commit 8e1d25b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4803,12 +4803,13 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
48034803
auto &nativeSchema =
48044804
IGM.getTypeInfo(funcResultTypeInContext).nativeReturnValueSchema(IGM);
48054805
if (result.empty() && !nativeSchema.empty()) {
4806-
// When we throw, we set the return values to undef.
4807-
nativeSchema.enumerateComponents([&](clang::CharUnits begin,
4808-
clang::CharUnits end,
4809-
llvm::Type *componentTy) {
4810-
nativeResultsStorage.push_back(llvm::UndefValue::get(componentTy));
4811-
});
4806+
if (!nativeSchema.requiresIndirect())
4807+
// When we throw, we set the return values to undef.
4808+
nativeSchema.enumerateComponents([&](clang::CharUnits begin,
4809+
clang::CharUnits end,
4810+
llvm::Type *componentTy) {
4811+
nativeResultsStorage.push_back(llvm::UndefValue::get(componentTy));
4812+
});
48124813
if (!error.empty())
48134814
nativeResultsStorage.push_back(error.claimNext());
48144815
nativeResults = nativeResultsStorage;

test/IRGen/async/throwing.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ func testSyncDoesntThrowThenAsyncDoesntThrow() async throws -> (Int, Int) {
130130
return (sync, async)
131131
}
132132

133+
public enum MyError : Error {
134+
case a
135+
}
136+
137+
// We used to crash on this.
138+
public func throwLarge() async throws -> (Int, Int, Int, Int, Int, Int, Int, Int) {
139+
throw MyError.a
140+
}
141+
133142
// CHECK: E()
134143
// CHECK: E()
135144
// CHECK: E()

0 commit comments

Comments
 (0)