mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 13:13:06 +00:00
Fix all optimization-inhibiting integer-to-pointer casts
Following from PR #2481, we replace all integer-to-pointer casts [which hide pointer provenance information (and thus inhibit optimizations)](https://clang.llvm.org/extra/clang-tidy/checks/performance/no-int-to-ptr.html) with equivalent operations that preserve this information. I have enabled the corresponding clang-tidy check in our static analysis CI so that we do not get bitten by this again in the future.
This commit is contained in:
committed by
Qi Wang
parent
4827bb17bd
commit
3e82f357bb
@@ -50,7 +50,7 @@ cache_bin_preincrement(cache_bin_info_t *infos, szind_t ninfos, void *alloc,
|
||||
assert(((uintptr_t)alloc & (computed_alignment - 1)) == 0);
|
||||
}
|
||||
|
||||
*(uintptr_t *)((uintptr_t)alloc + *cur_offset) =
|
||||
*(uintptr_t *)((byte_t *)alloc + *cur_offset) =
|
||||
cache_bin_preceding_junk;
|
||||
*cur_offset += sizeof(void *);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ cache_bin_preincrement(cache_bin_info_t *infos, szind_t ninfos, void *alloc,
|
||||
void
|
||||
cache_bin_postincrement(cache_bin_info_t *infos, szind_t ninfos, void *alloc,
|
||||
size_t *cur_offset) {
|
||||
*(uintptr_t *)((uintptr_t)alloc + *cur_offset) =
|
||||
*(uintptr_t *)((byte_t *)alloc + *cur_offset) =
|
||||
cache_bin_trailing_junk;
|
||||
*cur_offset += sizeof(void *);
|
||||
}
|
||||
@@ -71,12 +71,12 @@ cache_bin_init(cache_bin_t *bin, cache_bin_info_t *info, void *alloc,
|
||||
* will access the slots toward higher addresses (for the benefit of
|
||||
* adjacent prefetch).
|
||||
*/
|
||||
void *stack_cur = (void *)((uintptr_t)alloc + *cur_offset);
|
||||
void *stack_cur = (void *)((byte_t *)alloc + *cur_offset);
|
||||
void *full_position = stack_cur;
|
||||
uint16_t bin_stack_size = info->ncached_max * sizeof(void *);
|
||||
|
||||
*cur_offset += bin_stack_size;
|
||||
void *empty_position = (void *)((uintptr_t)alloc + *cur_offset);
|
||||
void *empty_position = (void *)((byte_t *)alloc + *cur_offset);
|
||||
|
||||
/* Init to the empty position. */
|
||||
bin->stack_head = (void **)empty_position;
|
||||
|
||||
Reference in New Issue
Block a user