From 2b2a0ddeac689030ff15737b6e50182bbd02f853 Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Mon, 17 Dec 2018 12:55:19 +0100 Subject: [PATCH] [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 Reviewed-by: Ulan Degenbaev Cr-Commit-Position: refs/heads/master@{#58292} --- include/v8config.h | 33 --------------------------------- src/allocation.cc | 2 +- src/profiler/cpu-profiler.cc | 2 +- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/include/v8config.h b/include/v8config.h index d30a7b07e1..e30a582e8f 100644 --- a/include/v8config.h +++ b/include/v8config.h @@ -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 class AlignOfHelper { char c; T t; }; } -# define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper) - sizeof(type)) -#endif - // Annotate a function indicating the caller must examine the return value. // Use like: // int foo() V8_WARN_UNUSED_RESULT; diff --git a/src/allocation.cc b/src/allocation.cc index 9d8ee2a128..9afd7b139e 100644 --- a/src/allocation.cc +++ b/src/allocation.cc @@ -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) { diff --git a/src/profiler/cpu-profiler.cc b/src/profiler/cpu-profiler.cc index 92e554292f..c67d5515db 100644 --- a/src/profiler/cpu-profiler.cc +++ b/src/profiler/cpu-profiler.cc @@ -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); }