diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-03-05 06:26:51 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-08-14 20:51:58 +0200 |
| commit | d5d72168fa325e3cbd893803c46564974e67a517 (patch) | |
| tree | ffbcf61452f2ce267a88de50bbeaed8e55e0c4f4 /compiler/rustc_arena | |
| parent | 67b1d2aec171b4971c8133c459edde277222d66c (diff) | |
| download | rust-d5d72168fa325e3cbd893803c46564974e67a517.tar.gz rust-d5d72168fa325e3cbd893803c46564974e67a517.zip | |
Allocate extra space to account for alignment losses
Diffstat (limited to 'compiler/rustc_arena')
| -rw-r--r-- | compiler/rustc_arena/src/lib.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index 7ab195a7c2d..108476a499f 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -410,7 +410,11 @@ impl Default for DroplessArena { } impl DroplessArena { - fn grow(&self, additional: usize) { + fn grow(&self, layout: Layout) { + // Add some padding so we can align `self.end` while + // stilling fitting in a `layout` allocation. + let additional = layout.size() + cmp::max(DROPLESS_ALIGNMENT, layout.align()) - 1; + unsafe { let mut chunks = self.chunks.borrow_mut(); let mut new_cap; @@ -429,7 +433,7 @@ impl DroplessArena { // Also ensure that this chunk can fit `additional`. new_cap = cmp::max(additional, new_cap); - let mut chunk = ArenaChunk::new(new_cap); + let mut chunk = ArenaChunk::new(align(new_cap, PAGE)); self.start.set(chunk.start()); // Align the end to DROPLESS_ALIGNMENT @@ -445,8 +449,8 @@ impl DroplessArena { #[inline(never)] #[cold] fn grow_and_alloc_raw(&self, layout: Layout) -> *mut u8 { - self.grow(layout.size()); - self.alloc_raw(layout) + self.grow(layout); + self.alloc_raw_without_grow(layout).unwrap() } #[inline(never)] |
