Commit 14324148 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

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/+/1862568Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64310}
parent d1437eca
......@@ -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)
......
......@@ -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) {
......
......@@ -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 &
......
......@@ -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
......
......@@ -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();
......
......@@ -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;
......
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment