Skip to content

Commit 0d94578

Browse files
committed
Only reinterpret cast once type is actually placed there
1 parent f1fa072 commit 0d94578

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

libc/src/__support/GPU/allocator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ struct Slab {
226226
// We attempt to place these next to each other.
227227
// TODO: We should coalesce these bits and use the result of `fetch_or` to
228228
// search for free bits in parallel.
229-
for (uint64_t mask = ~0ull; mask; mask = gpu::ballot(lane_mask, !result)) {
229+
for (uint64_t mask = lane_mask; mask;
230+
mask = gpu::ballot(lane_mask, !result)) {
230231
uint32_t id = impl::lane_count(uniform & mask);
231232
uint32_t index =
232233
(gpu::broadcast_value(lane_mask, impl::xorshift32(state)) + id) %
@@ -334,10 +335,10 @@ template <typename T> struct GuardPtr {
334335
cpp::MemoryOrder::RELAXED,
335336
cpp::MemoryOrder::RELAXED)) {
336337
count = cpp::numeric_limits<uint64_t>::max();
337-
T *mem = reinterpret_cast<T *>(impl::rpc_allocate(sizeof(T)));
338-
if (!mem)
338+
void *raw = impl::rpc_allocate(sizeof(T));
339+
if (!raw)
339340
return nullptr;
340-
new (mem) T(cpp::forward<Args>(args)...);
341+
T *mem = new (raw) T(cpp::forward<Args>(args)...);
341342

342343
cpp::atomic_thread_fence(cpp::MemoryOrder::RELEASE);
343344
ptr.store(mem, cpp::MemoryOrder::RELAXED);

0 commit comments

Comments
 (0)