Skip to content

Commit d83526d

Browse files
Merge pull request #3688 from swiftwasm/katei/fix-unreachable-coro-end-5.5
[5.5] [IRGen] Put 'ret void' instead of unreachable for non swiftasync cc
2 parents 862cbcc + d8da87a commit d83526d

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4906,7 +4906,15 @@ void irgen::emitAsyncReturn(
49064906
arguments.push_back(arg);
49074907

49084908
Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_end_async, arguments);
4909-
Builder.CreateUnreachable();
4909+
4910+
if (IGF.IGM.AsyncTailCallKind == llvm::CallInst::TCK_MustTail) {
4911+
Builder.CreateUnreachable();
4912+
} else {
4913+
// If target doesn't support musttail (e.g. WebAssembly), the function
4914+
// passed to coro.end.async can return control back to the caller.
4915+
// So use ret void instead of unreachable to allow it.
4916+
Builder.CreateRetVoid();
4917+
}
49104918
}
49114919

49124920
void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,

test/Concurrency/Runtime/async_task_sleep.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library) | %FileCheck %s --dump-input always
22
// REQUIRES: executable_test
33
// REQUIRES: concurrency
4-
// REQUIRES: libdispatch
54

65
// rdar://76038845
76
// REQUIRES: concurrency_runtime
87
// UNSUPPORTED: back_deployment_runtime
98

109
import _Concurrency
10+
#if canImport(Dispatch)
1111
// FIXME: should not depend on Dispatch
1212
import Dispatch
13+
#endif
1314

1415
@available(SwiftStdlib 5.5, *)
1516
@main struct Main {
@@ -21,6 +22,7 @@ import Dispatch
2122
}
2223

2324
static func testSleepDuration() async {
25+
#if canImport(Dispatch)
2426
let start = DispatchTime.now()
2527

2628
await Task.sleep(UInt64(pause))
@@ -29,6 +31,7 @@ import Dispatch
2931

3032
// assert that at least the specified time passed since calling `sleep`
3133
assert(stop >= (start + .nanoseconds(pause)))
34+
#endif
3235
}
3336

3437
static func testSleepDoesNotBlock() async {

test/Concurrency/Runtime/async_task_sleep_cancel.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library) | %FileCheck %s --dump-input always
22
// REQUIRES: executable_test
33
// REQUIRES: concurrency
4-
// REQUIRES: libdispatch
54

65
// rdar://76038845
76
// REQUIRES: concurrency_runtime
87
// UNSUPPORTED: back_deployment_runtime
98

109
import _Concurrency
10+
#if canImport(Dispatch)
1111
// FIXME: should not depend on Dispatch
1212
import Dispatch
13+
#endif
1314

1415
@available(SwiftStdlib 5.5, *)
1516
@main struct Main {
@@ -25,6 +26,7 @@ import Dispatch
2526
}
2627

2728
static func testSleepFinished() async {
29+
#if canImport(Dispatch)
2830
// CHECK-NEXT: Testing sleep that completes
2931
print("Testing sleep that completes")
3032
let start = DispatchTime.now()
@@ -39,6 +41,11 @@ import Dispatch
3941

4042
// CHECK-NEXT: Wakey wakey!
4143
print("Wakey wakey!")
44+
#else
45+
// dummy output to pass FileCheck
46+
print("Testing sleep that completes")
47+
print("Wakey wakey!")
48+
#endif
4249
}
4350

4451
static func testSleepMomentary() async {
@@ -75,6 +82,7 @@ import Dispatch
7582
}
7683

7784
static func testSleepCancelled() async {
85+
#if canImport(Dispatch)
7886
// CHECK-NEXT: Testing sleep that gets cancelled before it completes
7987
print("Testing sleep that gets cancelled before it completes")
8088
let start = DispatchTime.now()
@@ -110,5 +118,11 @@ import Dispatch
110118

111119
// CHECK-NEXT: Cancelled!
112120
print("Cancelled!")
121+
#else
122+
// dummy output to pass FileCheck
123+
print("Testing sleep that gets cancelled before it completes")
124+
print("Caught the cancellation error")
125+
print("Cancelled!")
126+
#endif
113127
}
114128
}

0 commit comments

Comments
 (0)