Skip to content

Commit 834816a

Browse files
committed
Check correct async SIL emission
This checks that we generate the correct SIL for async top-level code. @main sets things up and sets up the task containing `@async_Main`, which is the actual top-level code. It also verifies that we are correctly constructing the call to `exit` at the end of `@async_Main`, ensuring that the program actually terminates.
1 parent 431b666 commit 834816a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/SILGen/toplevel.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-emit-silgen -Xllvm -sil-full-demangle %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -Xllvm -sil-full-demangle %s | %FileCheck %s --check-prefixes='CHECK,SYNC-CHECK'
2+
// RUN: %target-swift-emit-silgen -Xllvm -sil-full-demangle -enable-experimental-async-top-level %s | %FileCheck %s --check-prefixes='CHECK,ASYNC-CHECK'
23

34
func markUsed<T>(_ t: T) {}
45

@@ -10,6 +11,15 @@ func trap() -> Never {
1011
// CHECK-LABEL: sil [ossa] @main
1112
// CHECK: bb0({{%.*}} : $Int32, {{%.*}} : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
1213

14+
// async setup call to @async_Main (this is in @main)
15+
// ASYNC-CHECK: [[ASYNC_MAIN:%[0-9]+]] = function_ref @async_Main : $@convention(thin) @async () -> ()
16+
// ASYNC-CHECK: [[THUNK:%[0-9]+]] = function_ref @$sIetH_yts5Error_pIegHrzo_TR
17+
18+
// Actual body of async top-level
19+
// ASYNC-CHECK-LABEL: sil hidden [ossa] @async_Main
20+
// ASYNC-CHECK: bb0:
21+
22+
1323
// -- initialize x
1424
// CHECK: alloc_global @$s8toplevel1xSiv
1525
// CHECK: [[X:%[0-9]+]] = global_addr @$s8toplevel1xSivp : $*Int
@@ -117,10 +127,11 @@ defer {
117127

118128

119129
// CHECK: [[RET:%[0-9]+]] = struct $Int32
120-
// CHECK: return [[RET]]
121-
122-
130+
// SYNC-CHECK: return [[RET]]
123131

132+
// ASYNC-CHECK: [[EXITFUNC:%[0-9]+]] = function_ref @exit
133+
// ASYNC-CHECK: apply [[EXITFUNC]]([[RET]]) : $@convention(c) (Int32) -> Never
134+
// ASYNC-CHECK: unreachable
124135

125136
// CHECK-LABEL: sil hidden [ossa] @$s8toplevel7print_xyyF
126137

0 commit comments

Comments
 (0)