| 1 | https://github.com/skvadrik/re2c/pull/555
|
| 2 |
|
| 3 | From 44125b74628d17f0a0a6cf9b51dd1f24169cd2d5 Mon Sep 17 00:00:00 2001
|
| 4 | From: Alexey Abramov <[email protected]>
|
| 5 | Date: Fri, 22 Aug 2025 08:10:08 +0200
|
| 6 | Subject: [PATCH] Use maximum alignment to ensure compatibility across all
|
| 7 | architectures.
|
| 8 |
|
| 9 | ---
|
| 10 | src/util/allocator.h | 14 ++++++++++----
|
| 11 | 1 file changed, 10 insertions(+), 4 deletions(-)
|
| 12 |
|
| 13 | diff --git a/src/util/allocator.h b/src/util/allocator.h
|
| 14 | index e6c85585b..56daf056f 100644
|
| 15 | |
| 16 | |
| 17 | @@ -3,6 +3,7 @@
|
| 18 |
|
| 19 | #include <stdint.h>
|
| 20 | #include <stdlib.h>
|
| 21 | +#include <stddef.h>
|
| 22 | #include <algorithm>
|
| 23 | #include <vector>
|
| 24 |
|
| 25 | @@ -78,11 +79,16 @@ class slab_allocator_t {
|
| 26 | };
|
| 27 |
|
| 28 | // Use maximum alignment.
|
| 29 | +// Use alignment based on pointer size: 32-bit platforms need stronger alignment
|
| 30 | +// for 64-bit types (double, long long), while 64-bit platforms are already
|
| 31 | +// sufficiently aligned with pointer-sized alignment.
|
| 32 | +constexpr size_t ALLOCATOR_ALIGNMENT = (sizeof(void*) == 4) ? alignof(max_align_t) : sizeof(void*);
|
| 33 | +
|
| 34 | // Use different types to prevent accidentally mixing allocators for data with different life spans.
|
| 35 | -using AstAllocator = slab_allocator_t<AllocatorKind::AST, 16 * 4096, sizeof(void*)>;
|
| 36 | -using IrAllocator = slab_allocator_t<AllocatorKind::IR, 16 * 4096, sizeof(void*)>;
|
| 37 | -using DfaAllocator = slab_allocator_t<AllocatorKind::DFA, 16 * 4096, sizeof(void*)>;
|
| 38 | -using OutAllocator = slab_allocator_t<AllocatorKind::OUT, 16 * 4096, sizeof(void*)>;
|
| 39 | +using AstAllocator = slab_allocator_t<AllocatorKind::AST, 16 * 4096, ALLOCATOR_ALIGNMENT>;
|
| 40 | +using IrAllocator = slab_allocator_t<AllocatorKind::IR, 16 * 4096, ALLOCATOR_ALIGNMENT>;
|
| 41 | +using DfaAllocator = slab_allocator_t<AllocatorKind::DFA, 16 * 4096, ALLOCATOR_ALIGNMENT>;
|
| 42 | +using OutAllocator = slab_allocator_t<AllocatorKind::OUT, 16 * 4096, ALLOCATOR_ALIGNMENT>;
|
| 43 |
|
| 44 | } // namespace re2c
|
| 45 |
|
| 46 | --
|
| 47 | 2.50.1
|
| 48 |
|