Skip to content

Commit 0e5f0b0

Browse files
authored
[TaskLocals] dont crash checking for taskgroup when in no task (#37681)
1 parent 99187c8 commit 0e5f0b0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ SWIFT_CC(swift)
411411
static bool swift_task_hasTaskGroupStatusRecordImpl() {
412412
auto task = swift_task_getCurrent();
413413

414+
// a group must be in a task, so if we're not in a task...
415+
// then, we certainly are not in a group either!
416+
if (!task)
417+
return false;
418+
414419
Optional<StatusRecordLockRecord> recordLockRecord;
415420

416421
// Acquire the status record lock.

test/Concurrency/Runtime/async_task_locals_synchronous_bind.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func printTaskLocal<V>(
3333
// ==== ------------------------------------------------------------------------
3434

3535
@available(SwiftStdlib 5.5, *)
36-
func synchronous_bind() async {
36+
func synchronous_bind() {
3737

3838
func synchronous() {
3939
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (1111)
@@ -45,14 +45,14 @@ func synchronous_bind() async {
4545
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (1111)
4646
}
4747

48-
await TL.$number.withValue(1111) {
48+
TL.$number.withValue(1111) {
4949
synchronous()
5050
}
5151
}
5252

5353
@available(SwiftStdlib 5.5, *)
5454
@main struct Main {
55-
static func main() async {
56-
await synchronous_bind()
55+
static func main() {
56+
synchronous_bind()
5757
}
5858
}

0 commit comments

Comments
 (0)