diff --git a/libc/src/__support/CPP/new.h b/libc/src/__support/CPP/new.h index 8694d9c47550..fe36de29468a 100644 --- a/libc/src/__support/CPP/new.h +++ b/libc/src/__support/CPP/new.h @@ -29,6 +29,14 @@ enum class align_val_t : size_t {}; namespace LIBC_NAMESPACE_DECL { +namespace cpp { +template [[nodiscard]] constexpr T *launder(T *p) { + static_assert(__has_builtin(__builtin_launder), + "cpp::launder requires __builtin_launder"); + return __builtin_launder(p); +} +} // namespace cpp + class AllocChecker { bool success = false; diff --git a/libc/src/__support/GPU/allocator.cpp b/libc/src/__support/GPU/allocator.cpp index 66ab155e5c29..5ea27a9c44b6 100644 --- a/libc/src/__support/GPU/allocator.cpp +++ b/libc/src/__support/GPU/allocator.cpp @@ -544,8 +544,8 @@ void deallocate(void *ptr) { return impl::rpc_free(ptr); // The original slab pointer is the 2MiB boundary using the given pointer. - Slab *slab = reinterpret_cast( - (reinterpret_cast(ptr) & ~SLAB_ALIGNMENT)); + Slab *slab = cpp::launder(reinterpret_cast( + (reinterpret_cast(ptr) & ~SLAB_ALIGNMENT))); slab->deallocate(ptr); release_slab(slab); }