Skip to content

Commit c9297b4

Browse files
committed
fix cast type in getting task record
1 parent bf5ef5a commit c9297b4

File tree

4 files changed

+10
-48
lines changed

4 files changed

+10
-48
lines changed

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
using namespace swift;
5252

53-
#if 1
53+
#if 0
5454
#define SWIFT_TASK_GROUP_DEBUG_LOG(group, fmt, ...) \
5555
fprintf(stderr, "[%#lx] [%s:%d](%s) group(%p%s) " fmt "\n", \
5656
(unsigned long)Thread::current().platformThreadId(), \
@@ -259,7 +259,7 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
259259
/// Any TaskGroup always IS its own TaskRecord.
260260
/// This allows us to easily get the group while cancellation is propagated throughout the task tree.
261261
TaskGroupTaskStatusRecord *getTaskRecord() {
262-
return reinterpret_cast<TaskGroupTaskStatusRecord *>(this);
262+
return static_cast<TaskGroupTaskStatusRecord *>(this);
263263
}
264264

265265
// ==== Queue operations ----------------------------------------------------
@@ -875,6 +875,8 @@ static void swift_taskGroup_initializeWithFlagsImpl(size_t rawGroupFlags,
875875
}
876876

877877
TaskGroupTaskStatusRecord *record = impl->getTaskRecord();
878+
assert(record->getKind() == swift::TaskStatusRecordKind::TaskGroup);
879+
878880
// ok, now that the group actually is initialized: attach it to the task
879881
addStatusRecord(record, [&](ActiveTaskStatus parentStatus) {
880882
// If the task has already been cancelled, reflect that immediately in

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ static bool swift_task_hasTaskGroupStatusRecordImpl() {
330330
[&](ActiveTaskStatus &status) {
331331
// Scan for the task group record within all the active records.
332332
for (auto record: status.records()) {
333+
fprintf(stderr, "[%s:%d](%s) CHECKING record = %d\n", __FILE_NAME__, __LINE__, __FUNCTION__, record->getKind());
333334
if (record->getKind() == TaskStatusRecordKind::TaskGroup) {
334335
foundTaskGroupRecord = true;
335336
return;

test/Concurrency/Runtime/async_task_locals_prevent_illegal_use_discarding_taskgroup.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ enum TL {
2222
func bindAroundGroupAddTask() async {
2323
await TL.$number.withValue(1111) { // ok
2424
await withTaskGroup(of: Int.self) { group in
25-
// CHECK: error: task-local: detected illegal task-local value binding at {{.*}}illegal_use.swift:[[# @LINE + 1]]
26-
TL.$number.withValue(2222) { // bad!
27-
print("Survived, inside withValue!") // CHECK-NOT: Survived, inside withValue!
28-
group.addTask {
29-
0 // don't actually perform the read, it would be unsafe.
30-
}
31-
}
32-
33-
print("Survived the illegal call!") // CHECK-NOT: Survived the illegal call!
34-
}
35-
}
36-
}
37-
38-
func bindAroundDiscardingGroupAddTask() async {
39-
await TL.$number.withValue(1111) { // ok
40-
await withDiscardingTaskGroup(of: Int.self) { group in
41-
// CHECK: error: task-local: detected illegal task-local value binding at {{.*}}illegal_use.swift:[[# @LINE + 1]]
25+
// CHECK: error: task-local: detected illegal task-local value binding at {{.*}}illegal_use_discarding_taskgroup.swift:[[# @LINE + 1]]
4226
TL.$number.withValue(2222) { // bad!
4327
print("Survived, inside withValue!") // CHECK-NOT: Survived, inside withValue!
4428
group.addTask {
@@ -53,10 +37,6 @@ func bindAroundDiscardingGroupAddTask() async {
5337

5438
@main struct Main {
5539
static func main() async {
56-
if CommandLine.arguments.contains("discarding-task-group") {
57-
await bindAroundGroupAddTask()
58-
} else {
59-
await bindAroundDiscardingGroupAddTask()
60-
}
40+
await bindAroundGroupAddTask()
6141
}
6242
}

test/Concurrency/Runtime/async_task_locals_prevent_illegal_use_taskgroup.swift

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,17 @@
1111
// REQUIRES: concurrency_runtime
1212
// UNSUPPORTED: back_deployment_runtime
1313

14-
@available(SwiftStdlib 5.1, *)
1514
enum TL {
1615
@TaskLocal
1716
static var number: Int = 2
1817
}
1918

2019
// ==== ------------------------------------------------------------------------
2120

22-
func bindAroundGroupAddTask() async {
23-
await TL.$number.withValue(1111) { // ok
24-
await withTaskGroup(of: Int.self) { group in
25-
// CHECK: error: task-local: detected illegal task-local value binding at {{.*}}illegal_use.swift:[[# @LINE + 1]]
26-
TL.$number.withValue(2222) { // bad!
27-
print("Survived, inside withValue!") // CHECK-NOT: Survived, inside withValue!
28-
group.addTask {
29-
0 // don't actually perform the read, it would be unsafe.
30-
}
31-
}
32-
33-
print("Survived the illegal call!") // CHECK-NOT: Survived the illegal call!
34-
}
35-
}
36-
}
37-
3821
func bindAroundDiscardingGroupAddTask() async {
3922
await TL.$number.withValue(1111) { // ok
40-
await withDiscardingTaskGroup(of: Int.self) { group in
41-
// CHECK: error: task-local: detected illegal task-local value binding at {{.*}}illegal_use.swift:[[# @LINE + 1]]
23+
await withTaskGroup(of: Int.self) { group in
24+
// CHECK: error: task-local: detected illegal task-local value binding at {{.*}}illegal_use_taskgroup.swift:[[# @LINE + 1]]
4225
TL.$number.withValue(2222) { // bad!
4326
print("Survived, inside withValue!") // CHECK-NOT: Survived, inside withValue!
4427
group.addTask {
@@ -53,10 +36,6 @@ func bindAroundDiscardingGroupAddTask() async {
5336

5437
@main struct Main {
5538
static func main() async {
56-
if CommandLine.arguments.contains("discarding-task-group") {
57-
await bindAroundGroupAddTask()
58-
} else {
59-
await bindAroundDiscardingGroupAddTask()
60-
}
39+
await bindAroundDiscardingGroupAddTask()
6140
}
6241
}

0 commit comments

Comments
 (0)