Skip to content

Commit 224dc12

Browse files
committed
[Test] Reduce stack usage in async_taskgroup_discarding_neverConsumingTasks.swift.
With optimizations disabled, the InlineArray initializer uses 512kB of stack space. This can overflow the stack depending on exactly how things are set up. Reduce stack usage by manually allocating memory for the array and initializing it as a pointer to Int. rdar://152420308
1 parent dd57d4d commit 224dc12

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/Concurrency/Runtime/async_taskgroup_discarding_neverConsumingTasks.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ func test_discardingTaskGroup_bigReturn() async {
9292
let array = await withDiscardingTaskGroup { group in
9393
group.addTask {}
9494
try? await Task.sleep(until: .now + .milliseconds(100), clock: .continuous)
95-
return InlineArray<32768, Int>(repeating: 12345)
95+
96+
// InlineArray.init(repeating:) uses a lot of stack space with optimizations
97+
// disabled, so set one up in a less friendly but less stack-consuming way.
98+
let ptr = UnsafeMutablePointer<InlineArray<32768, Int>>.allocate(capacity: 1)
99+
ptr.withMemoryRebound(to: Int.self, capacity: 32768) {
100+
$0.initialize(repeating: 12345, count: 32768)
101+
}
102+
// Deliberately leak `ptr` to avoid needing to save any temporaries.
103+
return ptr.pointee
96104
}
97105

98106
// CHECK: Huge return value produced: 12345 12345

0 commit comments

Comments
 (0)