[c++11] Replace V8_ALIGNOF by alignof

C++ introduces the {alignof} keyword, which evaluates to an integral
constant defining the alignment of the given type. This makes
{V8_ALIGNOF} redundant.

R=ulan@chromium.org

Bug: v8:8562
Change-Id: I15a4022c2c396afba96360f218d8a04b17a9a448
Reviewed-on: https://chromium-review.googlesource.com/c/1379938
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58292}
This commit is contained in:
Clemens Hammacher 2018-12-17 12:55:19 +01:00 committed by Commit Bot
parent 9abc7dae29
commit 2b2a0ddeac
3 changed files with 2 additions and 35 deletions

View File

@ -161,12 +161,8 @@
//
// C++11 feature detection
//
// V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported
//
// Compiler-specific feature detection
//
// V8_HAS___ALIGNOF - __alignof(type) operator supported
// V8_HAS___ALIGNOF__ - __alignof__(type) operator supported
// V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
// supported
// V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
@ -204,10 +200,6 @@
# define V8_CC_GNU 1
#endif
// Clang defines __alignof__ as alias for __alignof
# define V8_HAS___ALIGNOF 1
# define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
# define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
# define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE \
@ -248,8 +240,6 @@
# endif
# define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
# define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0))
// always_inline is available in gcc 4.0 but not very reliable until 4.4.
// Works around "sorry, unimplemented: inlining failed" build errors with
// older compilers.
@ -268,14 +258,10 @@
# define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0))
# define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0))
# if __cplusplus >= 201103L
# define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0))
# endif
#endif
#if defined(_MSC_VER)
# define V8_CC_MSVC 1
# define V8_HAS___ALIGNOF 1
# define V8_HAS_DECLSPEC_DEPRECATED 1
# define V8_HAS_DECLSPEC_NOINLINE 1
@ -354,25 +340,6 @@
#endif
// This macro returns alignment in bytes (an integer power of two) required for
// any instance of the given type, which is either complete type, an array type,
// or a reference type.
// Use like:
// size_t alignment = V8_ALIGNOF(double);
#if V8_HAS_CXX11_ALIGNOF
# define V8_ALIGNOF(type) alignof(type)
#elif V8_HAS___ALIGNOF
# define V8_ALIGNOF(type) __alignof(type)
#elif V8_HAS___ALIGNOF__
# define V8_ALIGNOF(type) __alignof__(type)
#else
// Note that alignment of a type within a struct can be less than the
// alignment of the type stand-alone (because of ancient ABIs), so this
// should only be used as a last resort.
namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; }
# define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type))
#endif
// Annotate a function indicating the caller must examine the return value.
// Use like:
// int foo() V8_WARN_UNUSED_RESULT;

View File

@ -122,7 +122,7 @@ void* AllocWithRetry(size_t size) {
}
void* AlignedAlloc(size_t size, size_t alignment) {
DCHECK_LE(V8_ALIGNOF(void*), alignment);
DCHECK_LE(alignof(void*), alignment);
DCHECK(base::bits::IsPowerOfTwo(alignment));
void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) {

View File

@ -226,7 +226,7 @@ void SamplingEventsProcessor::Run() {
}
void* SamplingEventsProcessor::operator new(size_t size) {
return AlignedAlloc(size, V8_ALIGNOF(SamplingEventsProcessor));
return AlignedAlloc(size, alignof(SamplingEventsProcessor));
}
void SamplingEventsProcessor::operator delete(void* ptr) { AlignedFree(ptr); }