Skip to content

Commit 4c87793

Browse files
authored
sanitizer_allocator.cpp: Ensure at least sizeof(void*) alignment
Some platforms (e.g. 64-bit CHERI) have stronger alignment requirements on values returned from allocators. For all other platforms this does not result in any functional change. Reviewed By: cjappl, vitalybuka Pull Request: llvm#84440
1 parent 1b8cff9 commit 4c87793

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void *RawInternalAlloc(uptr size, InternalAllocatorCache *cache,
5959

6060
static void *RawInternalRealloc(void *ptr, uptr size,
6161
InternalAllocatorCache *cache) {
62-
uptr alignment = 8;
62+
constexpr usize alignment = Max<usize>(8, sizeof(void *));
6363
if (cache == 0) {
6464
SpinMutexLock l(&internal_allocator_cache_mu);
6565
return internal_allocator()->Reallocate(&internal_allocator_cache, ptr,
@@ -137,7 +137,8 @@ void InternalAllocatorUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
137137
}
138138

139139
// LowLevelAllocator
140-
constexpr uptr kLowLevelAllocatorDefaultAlignment = 8;
140+
constexpr usize kLowLevelAllocatorDefaultAlignment =
141+
Max<usize>(8, sizeof(void *));
141142
constexpr uptr kMinNumPagesRounded = 16;
142143
constexpr uptr kMinRoundedSize = 65536;
143144
static uptr low_level_alloc_min_alignment = kLowLevelAllocatorDefaultAlignment;

0 commit comments

Comments
 (0)