diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp --- a/libcxx/src/memory.cpp +++ b/libcxx/src/memory.cpp @@ -194,7 +194,11 @@ if (size <= space) { char* p1 = static_cast(ptr); - char* p2 = reinterpret_cast(reinterpret_cast(p1 + (alignment - 1)) & -alignment); +#if __has_builtin(__builtin_align_up) + char* p2 = __builtin_align_up(p1, alignment); +#else + char* p2 = reinterpret_cast(reinterpret_cast(p1 + (alignment - 1)) & -alignment); +#endif size_t d = static_cast(p2 - p1); if (d <= space - size) {