Skip to content

Commit b2a2a76

Browse files
authored
Merge pull request #41955 from DougGregor/fix-async-let-stackallocator-5.6
[Concurrency] Have StackAllocator gracefully fail when passed a small firstSlabBuffer
2 parents ce8ad52 + 403ec1b commit b2a2a76

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stdlib/public/runtime/StackAllocator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ class StackAllocator {
259259
StackAllocator() : firstSlab(nullptr), firstSlabIsPreallocated(false) { }
260260

261261
/// Construct a StackAllocator with a pre-allocated first slab.
262-
StackAllocator(void *firstSlabBuffer, size_t bufferCapacity) {
262+
StackAllocator(void *firstSlabBuffer, size_t bufferCapacity) : StackAllocator() {
263+
// If the pre-allocated buffer can't hold a slab header, ignore it.
264+
if (bufferCapacity <= Slab::headerSize())
265+
return;
263266
char *start = (char *)llvm::alignAddr(firstSlabBuffer,
264267
llvm::Align(alignment));
265268
char *end = (char *)firstSlabBuffer + bufferCapacity;

0 commit comments

Comments
 (0)