Skip to content

Commit

Permalink
[libcxx] Fix std::align by using __builtin_align_up()
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Jul 1, 2019
1 parent d9531f5 commit dd01245
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libcxx/src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ align(size_t alignment, size_t size, void*& ptr, size_t& space)
if (size <= space)
{
char* p1 = static_cast<char*>(ptr);
#if __has_builtin(__builtin_align_up)
char* p2 = __builtin_align_up(p1, alignment);
#else
char* p2 = reinterpret_cast<char*>(reinterpret_cast<size_t>(p1 + (alignment - 1)) & -alignment);
#endif
size_t d = static_cast<size_t>(p2 - p1);
if (d <= space - size)
{
Expand Down

0 comments on commit dd01245

Please sign in to comment.