Skip to content

Commit e0d0af8

Browse files
committed
[Test] Make allocator_sanity.swift more robust on 32-bit.
This test attempts to allocate Int.max bytes and asserts that it crashes. However, this can actually succeed in (some) 32-bit environments, since Int.max is only 2^32-1 bytes there. This causes spurious test failures. Ensure the test crashes by making two gargantuan allocations. rdar://91687691
1 parent a79ea9d commit e0d0af8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test/Runtime/allocator_sanity.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ AllocationsTestSuite.test("absurd.allocation.misaligned") {
1818

1919
AllocationsTestSuite.test("absurd.allocation.gargantuan") {
2020
expectCrashLater()
21+
// There is a chance that we'll actually be able to allocate Int.max bytes on
22+
// 32-bit platforms, since they often have 4GB address spaces and Int.max is
23+
// 2GB minus one byte. Allocate twice to ensure failure. That will (attempt
24+
// to) allocate 4GB minus two bytes, and we'll definitely have more than two
25+
// bytes of other stuff in the process.
2126
let mustFail = UnsafeMutableRawPointer.allocate(byteCount: Int.max,
2227
alignment: 0)
28+
let mustFail2 = UnsafeMutableRawPointer.allocate(byteCount: Int.max,
29+
alignment: 0)
2330
expectUnreachable()
2431
_ = mustFail
32+
_ = mustFail2
2533
}
2634

2735
runAllTests()

0 commit comments

Comments
 (0)