Rename V8_CAN_HAVE_DCHECK_IN_CONSTEXPR to V8_HAS_CXX14_CONSTEXPR

DCHECKs are not really special, they just create a non-constexpr path
within an otherwise constexpr function. Since C++14, this is allowed.
Unfortunately, gcc only supports this since version 6, but we still
need to support gcc 5.

R=ulan@chromium.org

Change-Id: If74486144abafa5bbdcdbb9a567ee9295ac4cfc7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1862568
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64310}
This commit is contained in:
Clemens Backes 2019-10-15 15:44:45 +02:00 committed by Commit Bot
parent d1437ecaff
commit 143241483b
7 changed files with 17 additions and 12 deletions

View File

@ -290,9 +290,9 @@
// GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
# define V8_HAS_COMPUTED_GOTO 1
# if __cplusplus >= 201402L
# define V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 1
# endif
// Whether constexpr has full C++14 semantics, in particular that non-constexpr
// code is allowed as long as it's not executed for any constexpr instantiation.
# define V8_HAS_CXX14_CONSTEXPR 1
#elif defined(__GNUC__)
@ -328,6 +328,11 @@
// GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
#define V8_HAS_COMPUTED_GOTO (V8_GNUC_PREREQ(2, 0, 0))
// Whether constexpr has full C++14 semantics, in particular that non-constexpr
// code is allowed as long as it's not executed for any constexpr instantiation.
// GCC only supports this since version 6.
# define V8_HAS_CXX14_CONSTEXPR (V8_GNUC_PREREQ(6, 0, 0))
#endif
#if defined(_MSC_VER)

View File

@ -149,7 +149,7 @@ class BytecodeOperands : public AllStatic {
#undef OPERAND_SCALE_COUNT
static constexpr int OperandScaleAsIndex(OperandScale operand_scale) {
#ifdef V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
#ifdef DEBUG
int result = static_cast<int>(operand_scale) >> 1;
switch (operand_scale) {

View File

@ -88,7 +88,7 @@ inline constexpr uint16_t ToLatin1Lower(uint16_t ch) {
// Does not work for U+00DF (sharp-s), U+00B5 (micron), U+00FF.
inline constexpr uint16_t ToLatin1Upper(uint16_t ch) {
#if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(ch != 0xDF && ch != 0xB5 && ch != 0xFF);
#endif
return ch &

View File

@ -26,7 +26,7 @@ class Smi : public Object {
// in that we want them to be constexprs.
constexpr Smi() : Object() {}
explicit constexpr Smi(Address ptr) : Object(ptr) {
#if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(HAS_SMI_TAG(ptr));
#endif
}
@ -47,7 +47,7 @@ class Smi : public Object {
// Convert a value to a Smi object.
static inline constexpr Smi FromInt(int value) {
#if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(Smi::IsValid(value));
#endif
return Smi(Internals::IntToSmi(value));
@ -75,7 +75,7 @@ class Smi : public Object {
// Returns whether value can be represented in a Smi.
static inline bool constexpr IsValid(intptr_t value) {
#if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(Internals::IsValidSmi(value) ==
(value >= kMinValue && value <= kMaxValue));
#endif

View File

@ -88,7 +88,7 @@ class TaggedImpl {
// Returns true if this tagged value is a strong pointer to a HeapObject.
constexpr inline bool IsStrong() const {
#ifdef V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_IMPLIES(!kCanBeWeak, !IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_));
#endif
return kCanBeWeak ? HAS_STRONG_HEAP_OBJECT_TAG(ptr_) : !IsSmi();

View File

@ -59,7 +59,7 @@ inline int BoolToInt(bool b) { return b ? 1 : 0; }
// branch.
template <typename T, typename U>
inline constexpr bool IsInRange(T value, U lower_limit, U higher_limit) {
#if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(lower_limit <= higher_limit);
#endif
STATIC_ASSERT(sizeof(U) <= sizeof(T));
@ -342,7 +342,7 @@ class BitField final {
// Returns a type U with the bit field value encoded.
static constexpr U encode(T value) {
#if V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(is_valid(value));
#endif
return static_cast<U>(value) << kShift;

View File

@ -23,7 +23,7 @@ class Vector {
constexpr Vector() : start_(nullptr), length_(0) {}
constexpr Vector(T* data, size_t length) : start_(data), length_(length) {
#ifdef V8_CAN_HAVE_DCHECK_IN_CONSTEXPR
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(length == 0 || data != nullptr);
#endif
}