diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -382,13 +382,13 @@ # define _LIBCPP_NO_CFI #endif -#ifndef _LIBCPP_CXX03_LANG -# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) -#elif defined(_LIBCPP_COMPILER_CLANG_BASED) -# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) -#else -# error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang" -#endif +# ifdef _LIBCPP_CXX03_LANG +# ifdef _LIBCPP_COMPILER_CLANG_BASED +# define alignof(_Tp) _Alignof(_Tp) +# else +# error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang" +# endif +# endif #define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) @@ -403,7 +403,7 @@ # define _ALIGNAS_TYPE(x) alignas(x) # define _ALIGNAS(x) alignas(x) #else -# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) +# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(alignof(x)))) # define _ALIGNAS(x) __attribute__((__aligned__(x))) #endif @@ -463,7 +463,7 @@ #elif defined(_LIBCPP_COMPILER_GCC) #define _ALIGNAS(x) __attribute__((__aligned__(x))) -#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) +#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(alignof(x)))) #define _LIBCPP_NORETURN __attribute__((noreturn)) @@ -505,7 +505,7 @@ #elif defined(_LIBCPP_COMPILER_IBM) #define _ALIGNAS(x) __attribute__((__aligned__(x))) -#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) +#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(alignof(x)))) #define _ATTRIBUTE(x) __attribute__((x)) #define _LIBCPP_NORETURN __attribute__((noreturn)) diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h --- a/libcxx/include/__functional/function.h +++ b/libcxx/include/__functional/function.h @@ -582,7 +582,7 @@ struct __use_small_storage : public integral_constant< bool, sizeof(_Fun) <= sizeof(__policy_storage) && - _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) && + alignof(_Fun) <= alignof(__policy_storage) && is_trivially_copy_constructible<_Fun>::value && is_trivially_destructible<_Fun>::value> {}; diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h --- a/libcxx/include/__memory/allocator.h +++ b/libcxx/include/__memory/allocator.h @@ -103,7 +103,7 @@ if (__libcpp_is_constant_evaluated()) { return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); } else { - return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); + return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), alignof(_Tp))); } } @@ -119,7 +119,7 @@ if (__libcpp_is_constant_evaluated()) { ::operator delete(__p); } else { - _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), alignof(_Tp)); } } @@ -192,7 +192,7 @@ if (__libcpp_is_constant_evaluated()) { return static_cast(::operator new(__n * sizeof(_Tp))); } else { - return static_cast(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); + return static_cast(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), alignof(_Tp))); } } @@ -208,7 +208,7 @@ if (__libcpp_is_constant_evaluated()) { ::operator delete(const_cast<_Tp*>(__p)); } else { - _VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + _VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), alignof(_Tp)); } } diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -355,7 +355,7 @@ } }; - static_assert(_LIBCPP_ALIGNOF(_Storage) == _LIBCPP_ALIGNOF(_CompressedPair), ""); + static_assert(alignof(_Storage) == alignof(_CompressedPair), ""); static_assert(sizeof(_Storage) == sizeof(_CompressedPair), ""); _Storage __storage_; }; diff --git a/libcxx/include/__memory/temporary_buffer.h b/libcxx/include/__memory/temporary_buffer.h --- a/libcxx/include/__memory/temporary_buffer.h +++ b/libcxx/include/__memory/temporary_buffer.h @@ -35,7 +35,7 @@ while (__n > 0) { #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) - if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) + if (__is_overaligned_for_new(alignof(_Tp))) { align_val_t __al = align_val_t(alignment_of<_Tp>::value); @@ -46,7 +46,7 @@ __n * sizeof(_Tp), nothrow)); } #else - if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) + if (__is_overaligned_for_new(alignof(_Tp))) { // Since aligned operator new is unavailable, return an empty // buffer rather than one with invalid alignment. @@ -70,7 +70,7 @@ inline _LIBCPP_INLINE_VISIBILITY void return_temporary_buffer(_Tp* __p) _NOEXCEPT { - _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp)); + _VSTD::__libcpp_deallocate_unsized((void*)__p, alignof(_Tp)); } struct __return_temporary_buffer diff --git a/libcxx/include/experimental/coroutine b/libcxx/include/experimental/coroutine --- a/libcxx/include/experimental/coroutine +++ b/libcxx/include/experimental/coroutine @@ -204,7 +204,7 @@ _LIBCPP_INLINE_VISIBILITY _Promise& promise() const { return *static_cast<_Promise*>( - __builtin_coro_promise(this->__handle_, _LIBCPP_ALIGNOF(_Promise), false)); + __builtin_coro_promise(this->__handle_, alignof(_Promise), false)); } public: @@ -244,7 +244,7 @@ coroutine_handle __tmp; __tmp.__handle_ = __builtin_coro_promise( _VSTD::addressof(const_cast<_RawPromise&>(__promise)), - _LIBCPP_ALIGNOF(_Promise), true); + alignof(_Promise), true); return __tmp; } }; @@ -262,7 +262,7 @@ _LIBCPP_INLINE_VISIBILITY _Promise& promise() const { return *static_cast<_Promise*>( - __builtin_coro_promise(this->__handle_, _LIBCPP_ALIGNOF(_Promise), false)); + __builtin_coro_promise(this->__handle_, alignof(_Promise), false)); } _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return true; } diff --git a/libcxx/include/experimental/memory_resource b/libcxx/include/experimental/memory_resource --- a/libcxx/include/experimental/memory_resource +++ b/libcxx/include/experimental/memory_resource @@ -97,7 +97,7 @@ // 8.5, memory.resource class _LIBCPP_TYPE_VIS memory_resource { - static const size_t __max_align = _LIBCPP_ALIGNOF(max_align_t); + static const size_t __max_align = alignof(max_align_t); // 8.5.2, memory.resource.public public: @@ -186,7 +186,7 @@ if (__n > __max_size()) __throw_bad_array_new_length(); return static_cast<_ValueType*>( - __res_->allocate(__n * sizeof(_ValueType), _LIBCPP_ALIGNOF(_ValueType)) + __res_->allocate(__n * sizeof(_ValueType), alignof(_ValueType)) ); } @@ -194,7 +194,7 @@ void deallocate(_ValueType * __p, size_t __n) _NOEXCEPT { _LIBCPP_ASSERT(__n <= __max_size(), "deallocate called for size which exceeds max_size()"); - __res_->deallocate(__p, __n * sizeof(_ValueType), _LIBCPP_ALIGNOF(_ValueType)); + __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); } template @@ -341,7 +341,7 @@ && is_same::value && is_same::value, ""); - static const size_t _MaxAlign = _LIBCPP_ALIGNOF(max_align_t); + static const size_t _MaxAlign = alignof(max_align_t); using _Alloc = typename _CTraits::template rebind_alloc< typename aligned_storage<_MaxAlign, _MaxAlign>::type diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -1064,7 +1064,7 @@ struct __temp_value { typedef allocator_traits<_Alloc> _Traits; - typename aligned_storage::type __v; + typename aligned_storage::type __v; _Alloc &__a; _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } @@ -1125,13 +1125,13 @@ template _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE static __holder_t __allocate_type(size_t __n) { - return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + return __allocate_bytes(__n * sizeof(_Tp), alignof(_Tp)); } template _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { - __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + __deallocate_bytes(__p, __n * sizeof(_Tp), alignof(_Tp)); } }; diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -1260,7 +1260,7 @@ // alignment_of template struct _LIBCPP_TEMPLATE_VIS alignment_of - : public integral_constant {}; + : public integral_constant {}; #if _LIBCPP_STD_VER > 14 template diff --git a/libcxx/test/libcxx/libcpp_alignof.pass.cpp b/libcxx/test/libcxx/libcpp_alignof.pass.cpp deleted file mode 100644 --- a/libcxx/test/libcxx/libcpp_alignof.pass.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Test that _LIBCPP_ALIGNOF acts the same as the C++11 keyword `alignof`, and -// not as the GNU extension `__alignof`. The former returns the minimal required -// alignment for a type, whereas the latter returns the preferred alignment. -// -// See llvm.org/PR39713 - -#include -#include "test_macros.h" - -template -void test() { - static_assert(_LIBCPP_ALIGNOF(T) == std::alignment_of::value, ""); - static_assert(_LIBCPP_ALIGNOF(T) == TEST_ALIGNOF(T), ""); -#if TEST_STD_VER >= 11 - static_assert(_LIBCPP_ALIGNOF(T) == alignof(T), ""); -#endif -#ifdef TEST_COMPILER_CLANG - static_assert(_LIBCPP_ALIGNOF(T) == _Alignof(T), ""); -#endif -} - -int main(int, char**) { - test(); - test(); - test(); - test(); - return 0; -}