Remove workarounds for [D]CHECK()s in constexpr functions.
We're now using C++14, so we can use [D]CHECK()s directly
in constexpr functions. Remove the C++11 workaround macros
([D]CHECK_CONSTEXPR) and C++ version checks. Also remove the
'static' qualifier from inline functions in affected files.
Test: m test-art-host
Change-Id: I0f962ad75e4efe9b65325d022cd272b229574222
diff --git a/compiler/optimizing/code_generator_arm.h b/compiler/optimizing/code_generator_arm.h
index a07dd6b..ac10e23 100644
--- a/compiler/optimizing/code_generator_arm.h
+++ b/compiler/optimizing/code_generator_arm.h
@@ -63,9 +63,9 @@
DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
};
-static constexpr DRegister FromLowSToD(SRegister reg) {
- return DCHECK_CONSTEXPR(reg % 2 == 0, , D0)
- static_cast<DRegister>(reg / 2);
+constexpr DRegister FromLowSToD(SRegister reg) {
+ DCHECK_EQ(reg % 2, 0);
+ return static_cast<DRegister>(reg / 2);
}
diff --git a/runtime/base/bit_utils.h b/runtime/base/bit_utils.h
index f279f45..378371d 100644
--- a/runtime/base/bit_utils.h
+++ b/runtime/base/bit_utils.h
@@ -28,43 +28,35 @@
namespace art {
template<typename T>
-static constexpr int CLZ(T x) {
+constexpr int CLZ(T x) {
static_assert(std::is_integral<T>::value, "T must be integral");
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
static_assert(sizeof(T) <= sizeof(long long), // NOLINT [runtime/int] [4]
"T too large, must be smaller than long long");
- return
- DCHECK_CONSTEXPR(x != 0, "x must not be zero", T(0))
- (sizeof(T) == sizeof(uint32_t))
- ? __builtin_clz(x)
- : __builtin_clzll(x);
+ DCHECK_NE(x, 0u);
+ return (sizeof(T) == sizeof(uint32_t)) ? __builtin_clz(x) : __builtin_clzll(x);
}
template<typename T>
-static constexpr int CTZ(T x) {
+constexpr int CTZ(T x) {
static_assert(std::is_integral<T>::value, "T must be integral");
// It is not unreasonable to ask for trailing zeros in a negative number. As such, do not check
// that T is an unsigned type.
static_assert(sizeof(T) <= sizeof(long long), // NOLINT [runtime/int] [4]
"T too large, must be smaller than long long");
- return
- DCHECK_CONSTEXPR(x != 0, "x must not be zero", T(0))
- (sizeof(T) == sizeof(uint32_t))
- ? __builtin_ctz(x)
- : __builtin_ctzll(x);
+ DCHECK_NE(x, static_cast<T>(0));
+ return (sizeof(T) == sizeof(uint32_t)) ? __builtin_ctz(x) : __builtin_ctzll(x);
}
// Return the number of 1-bits in `x`.
template<typename T>
-static constexpr int POPCOUNT(T x) {
- return (sizeof(T) == sizeof(uint32_t))
- ? __builtin_popcount(x)
- : __builtin_popcountll(x);
+constexpr int POPCOUNT(T x) {
+ return (sizeof(T) == sizeof(uint32_t)) ? __builtin_popcount(x) : __builtin_popcountll(x);
}
// Find the bit position of the most significant bit (0-based), or -1 if there were no bits set.
template <typename T>
-static constexpr ssize_t MostSignificantBit(T value) {
+constexpr ssize_t MostSignificantBit(T value) {
static_assert(std::is_integral<T>::value, "T must be integral");
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
static_assert(std::numeric_limits<T>::radix == 2, "Unexpected radix!");
@@ -73,7 +65,7 @@
// Find the bit position of the least significant bit (0-based), or -1 if there were no bits set.
template <typename T>
-static constexpr ssize_t LeastSignificantBit(T value) {
+constexpr ssize_t LeastSignificantBit(T value) {
static_assert(std::is_integral<T>::value, "T must be integral");
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
return (value == 0) ? -1 : CTZ(value);
@@ -81,12 +73,12 @@
// How many bits (minimally) does it take to store the constant 'value'? i.e. 1 for 1, 3 for 5, etc.
template <typename T>
-static constexpr size_t MinimumBitsToStore(T value) {
+constexpr size_t MinimumBitsToStore(T value) {
return static_cast<size_t>(MostSignificantBit(value) + 1);
}
template <typename T>
-static constexpr inline T RoundUpToPowerOfTwo(T x) {
+constexpr T RoundUpToPowerOfTwo(T x) {
static_assert(std::is_integral<T>::value, "T must be integral");
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
// NOTE: Undefined if x > (1 << (std::numeric_limits<T>::digits - 1)).
@@ -94,14 +86,14 @@
}
template<typename T>
-static constexpr bool IsPowerOfTwo(T x) {
+constexpr bool IsPowerOfTwo(T x) {
static_assert(std::is_integral<T>::value, "T must be integral");
// TODO: assert unsigned. There is currently many uses with signed values.
return (x & (x - 1)) == 0;
}
template<typename T>
-static inline int WhichPowerOf2(T x) {
+constexpr int WhichPowerOf2(T x) {
static_assert(std::is_integral<T>::value, "T must be integral");
// TODO: assert unsigned. There is currently many uses with signed values.
DCHECK((x != 0) && IsPowerOfTwo(x));
@@ -111,53 +103,52 @@
// For rounding integers.
// Note: Omit the `n` from T type deduction, deduce only from the `x` argument.
template<typename T>
-static constexpr T RoundDown(T x, typename Identity<T>::type n) WARN_UNUSED;
+constexpr T RoundDown(T x, typename Identity<T>::type n) WARN_UNUSED;
template<typename T>
-static constexpr T RoundDown(T x, typename Identity<T>::type n) {
- return
- DCHECK_CONSTEXPR(IsPowerOfTwo(n), , T(0))
- (x & -n);
+constexpr T RoundDown(T x, typename Identity<T>::type n) {
+ DCHECK(IsPowerOfTwo(n));
+ return (x & -n);
}
template<typename T>
-static constexpr T RoundUp(T x, typename std::remove_reference<T>::type n) WARN_UNUSED;
+constexpr T RoundUp(T x, typename std::remove_reference<T>::type n) WARN_UNUSED;
template<typename T>
-static constexpr T RoundUp(T x, typename std::remove_reference<T>::type n) {
+constexpr T RoundUp(T x, typename std::remove_reference<T>::type n) {
return RoundDown(x + n - 1, n);
}
// For aligning pointers.
template<typename T>
-static inline T* AlignDown(T* x, uintptr_t n) WARN_UNUSED;
+inline T* AlignDown(T* x, uintptr_t n) WARN_UNUSED;
template<typename T>
-static inline T* AlignDown(T* x, uintptr_t n) {
+inline T* AlignDown(T* x, uintptr_t n) {
return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uintptr_t>(x), n));
}
template<typename T>
-static inline T* AlignUp(T* x, uintptr_t n) WARN_UNUSED;
+inline T* AlignUp(T* x, uintptr_t n) WARN_UNUSED;
template<typename T>
-static inline T* AlignUp(T* x, uintptr_t n) {
+inline T* AlignUp(T* x, uintptr_t n) {
return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uintptr_t>(x), n));
}
template<int n, typename T>
-static constexpr bool IsAligned(T x) {
+constexpr bool IsAligned(T x) {
static_assert((n & (n - 1)) == 0, "n is not a power of two");
return (x & (n - 1)) == 0;
}
template<int n, typename T>
-static inline bool IsAligned(T* x) {
+inline bool IsAligned(T* x) {
return IsAligned<n>(reinterpret_cast<const uintptr_t>(x));
}
template<typename T>
-static inline bool IsAlignedParam(T x, int n) {
+inline bool IsAlignedParam(T x, int n) {
return (x & (n - 1)) == 0;
}
@@ -175,9 +166,9 @@
// Like sizeof, but count how many bits a type takes. Pass type explicitly.
template <typename T>
-static constexpr size_t BitSizeOf() {
+constexpr size_t BitSizeOf() {
static_assert(std::is_integral<T>::value, "T must be integral");
- typedef typename std::make_unsigned<T>::type unsigned_type;
+ using unsigned_type = typename std::make_unsigned<T>::type;
static_assert(sizeof(T) == sizeof(unsigned_type), "Unexpected type size mismatch!");
static_assert(std::numeric_limits<unsigned_type>::radix == 2, "Unexpected radix!");
return std::numeric_limits<unsigned_type>::digits;
@@ -185,29 +176,29 @@
// Like sizeof, but count how many bits a type takes. Infers type from parameter.
template <typename T>
-static constexpr size_t BitSizeOf(T /*x*/) {
+constexpr size_t BitSizeOf(T /*x*/) {
return BitSizeOf<T>();
}
-static inline uint16_t Low16Bits(uint32_t value) {
+inline uint16_t Low16Bits(uint32_t value) {
return static_cast<uint16_t>(value);
}
-static inline uint16_t High16Bits(uint32_t value) {
+inline uint16_t High16Bits(uint32_t value) {
return static_cast<uint16_t>(value >> 16);
}
-static inline uint32_t Low32Bits(uint64_t value) {
+inline uint32_t Low32Bits(uint64_t value) {
return static_cast<uint32_t>(value);
}
-static inline uint32_t High32Bits(uint64_t value) {
+inline uint32_t High32Bits(uint64_t value) {
return static_cast<uint32_t>(value >> 32);
}
// Check whether an N-bit two's-complement representation can hold value.
template <typename T>
-static inline bool IsInt(size_t N, T value) {
+inline bool IsInt(size_t N, T value) {
if (N == BitSizeOf<T>()) {
return true;
} else {
@@ -219,15 +210,14 @@
}
template <typename T>
-static constexpr T GetIntLimit(size_t bits) {
- return
- DCHECK_CONSTEXPR(bits > 0, "bits cannot be zero", 0)
- DCHECK_CONSTEXPR(bits < BitSizeOf<T>(), "kBits must be < max.", 0)
- static_cast<T>(1) << (bits - 1);
+constexpr T GetIntLimit(size_t bits) {
+ DCHECK_NE(bits, 0u);
+ DCHECK_LT(bits, BitSizeOf<T>());
+ return static_cast<T>(1) << (bits - 1);
}
template <size_t kBits, typename T>
-static constexpr bool IsInt(T value) {
+constexpr bool IsInt(T value) {
static_assert(kBits > 0, "kBits cannot be zero.");
static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max.");
static_assert(std::is_signed<T>::value, "Needs a signed type.");
@@ -239,7 +229,7 @@
}
template <size_t kBits, typename T>
-static constexpr bool IsUint(T value) {
+constexpr bool IsUint(T value) {
static_assert(kBits > 0, "kBits cannot be zero.");
static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max.");
static_assert(std::is_integral<T>::value, "Needs an integral type.");
@@ -247,17 +237,17 @@
// trivially true.
// NOTE: To avoid triggering assertion in GetIntLimit(kBits+1) if kBits+1==BitSizeOf<T>(),
// use GetIntLimit(kBits)*2u. The unsigned arithmetic works well for us if it overflows.
+ using unsigned_type = typename std::make_unsigned<T>::type;
return (0 <= value) &&
(kBits == BitSizeOf<T>() ||
- (static_cast<typename std::make_unsigned<T>::type>(value) <=
- GetIntLimit<typename std::make_unsigned<T>::type>(kBits) * 2u - 1u));
+ (static_cast<unsigned_type>(value) <= GetIntLimit<unsigned_type>(kBits) * 2u - 1u));
}
template <size_t kBits, typename T>
-static constexpr bool IsAbsoluteUint(T value) {
+constexpr bool IsAbsoluteUint(T value) {
static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max.");
static_assert(std::is_integral<T>::value, "Needs an integral type.");
- typedef typename std::make_unsigned<T>::type unsigned_type;
+ using unsigned_type = typename std::make_unsigned<T>::type;
return (kBits == BitSizeOf<T>())
? true
: IsUint<kBits>(value < 0
@@ -267,29 +257,26 @@
// Generate maximum/minimum values for signed/unsigned n-bit integers
template <typename T>
-static constexpr T MaxInt(size_t bits) {
- return
- DCHECK_CONSTEXPR(std::is_unsigned<T>::value || bits > 0, "bits cannot be zero for signed", 0)
- DCHECK_CONSTEXPR(bits <= BitSizeOf<T>(), "kBits must be < max.", 0)
- bits == BitSizeOf<T>()
- ? std::numeric_limits<T>::max()
- : std::is_signed<T>::value
- ? (bits == 1
- ? 0
- : static_cast<T>(MaxInt<typename std::make_unsigned<T>::type>(bits - 1)))
- : static_cast<T>(UINT64_C(1) << bits) - static_cast<T>(1);
+constexpr T MaxInt(size_t bits) {
+ DCHECK(std::is_unsigned<T>::value || bits > 0u) << "bits cannot be zero for signed.";
+ DCHECK_LE(bits, BitSizeOf<T>());
+ using unsigned_type = typename std::make_unsigned<T>::type;
+ return bits == BitSizeOf<T>()
+ ? std::numeric_limits<T>::max()
+ : std::is_signed<T>::value
+ ? ((bits == 1u) ? 0 : static_cast<T>(MaxInt<unsigned_type>(bits - 1)))
+ : static_cast<T>(UINT64_C(1) << bits) - static_cast<T>(1);
}
template <typename T>
-static constexpr T MinInt(size_t bits) {
- return
- DCHECK_CONSTEXPR(std::is_unsigned<T>::value || bits > 0, "bits cannot be zero for signed", 0)
- DCHECK_CONSTEXPR(bits <= BitSizeOf<T>(), "kBits must be < max.", 0)
- bits == BitSizeOf<T>()
- ? std::numeric_limits<T>::min()
- : std::is_signed<T>::value
- ? (bits == 1 ? -1 : static_cast<T>(-1) - MaxInt<T>(bits))
- : static_cast<T>(0);
+constexpr T MinInt(size_t bits) {
+ DCHECK(std::is_unsigned<T>::value || bits > 0) << "bits cannot be zero for signed.";
+ DCHECK_LE(bits, BitSizeOf<T>());
+ return bits == BitSizeOf<T>()
+ ? std::numeric_limits<T>::min()
+ : std::is_signed<T>::value
+ ? ((bits == 1u) ? -1 : static_cast<T>(-1) - MaxInt<T>(bits))
+ : static_cast<T>(0);
}
// Using the Curiously Recurring Template Pattern to implement everything shared
diff --git a/runtime/base/iteration_range.h b/runtime/base/iteration_range.h
index cf02d32..54ab174 100644
--- a/runtime/base/iteration_range.h
+++ b/runtime/base/iteration_range.h
@@ -45,12 +45,12 @@
};
template <typename Iter>
-static inline IterationRange<Iter> MakeIterationRange(const Iter& begin_it, const Iter& end_it) {
+inline IterationRange<Iter> MakeIterationRange(const Iter& begin_it, const Iter& end_it) {
return IterationRange<Iter>(begin_it, end_it);
}
template <typename Iter>
-static inline IterationRange<Iter> MakeEmptyIterationRange(const Iter& it) {
+inline IterationRange<Iter> MakeEmptyIterationRange(const Iter& it) {
return IterationRange<Iter>(it, it);
}
diff --git a/runtime/base/logging.h b/runtime/base/logging.h
index ac21a3f..f43cb8b 100644
--- a/runtime/base/logging.h
+++ b/runtime/base/logging.h
@@ -161,16 +161,6 @@
} \
} while (false)
-// CHECK that can be used in a constexpr function. For example,
-// constexpr int half(int n) {
-// return
-// DCHECK_CONSTEXPR(n >= 0, , 0)
-// CHECK_CONSTEXPR((n & 1) == 0), << "Extra debugging output: n = " << n, 0)
-// n / 2;
-// }
-#define CHECK_CONSTEXPR(x, out, dummy) \
- (UNLIKELY(!(x))) ? (LOG(::art::FATAL) << "Check failed: " << #x out, dummy) :
-
// DCHECKs are debug variants of CHECKs only enabled in debug builds. Generally CHECK should be
// used unless profiling identifies a CHECK as being in performance critical code.
@@ -189,11 +179,6 @@
#define DCHECK_GT(x, y) if (::art::kEnableDChecks) CHECK_GT(x, y)
#define DCHECK_STREQ(s1, s2) if (::art::kEnableDChecks) CHECK_STREQ(s1, s2)
#define DCHECK_STRNE(s1, s2) if (::art::kEnableDChecks) CHECK_STRNE(s1, s2)
-#if defined(NDEBUG)
-#define DCHECK_CONSTEXPR(x, out, dummy)
-#else
-#define DCHECK_CONSTEXPR(x, out, dummy) CHECK_CONSTEXPR(x, out, dummy)
-#endif
// Temporary class created to evaluate the LHS and RHS, used with MakeEagerEvaluator to infer the
// types of LHS and RHS.
@@ -206,7 +191,7 @@
// Helper function for CHECK_xx.
template <typename LHS, typename RHS>
-static inline constexpr EagerEvaluator<LHS, RHS> MakeEagerEvaluator(LHS lhs, RHS rhs) {
+constexpr EagerEvaluator<LHS, RHS> MakeEagerEvaluator(LHS lhs, RHS rhs) {
return EagerEvaluator<LHS, RHS>(lhs, rhs);
}
diff --git a/runtime/dex_instruction_utils.h b/runtime/dex_instruction_utils.h
index 2849cd8..72d8244 100644
--- a/runtime/dex_instruction_utils.h
+++ b/runtime/dex_instruction_utils.h
@@ -134,74 +134,54 @@
return Instruction::ADD_INT_2ADDR <= code && code <= Instruction::REM_DOUBLE_2ADDR;
}
-// TODO: Remove the #if guards below when we fully migrate to C++14.
-
constexpr bool IsInvokeInstructionRange(Instruction::Code opcode) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionInvoke(opcode));
-#endif
return opcode >= Instruction::INVOKE_VIRTUAL_RANGE;
}
constexpr DexInvokeType InvokeInstructionType(Instruction::Code opcode) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionInvoke(opcode));
-#endif
return static_cast<DexInvokeType>(IsInvokeInstructionRange(opcode)
? (opcode - Instruction::INVOKE_VIRTUAL_RANGE)
: (opcode - Instruction::INVOKE_VIRTUAL));
}
constexpr DexMemAccessType IGetMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionIGet(code));
-#endif
return static_cast<DexMemAccessType>(code - Instruction::IGET);
}
constexpr DexMemAccessType IPutMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionIPut(code));
-#endif
return static_cast<DexMemAccessType>(code - Instruction::IPUT);
}
constexpr DexMemAccessType SGetMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionSGet(code));
-#endif
return static_cast<DexMemAccessType>(code - Instruction::SGET);
}
constexpr DexMemAccessType SPutMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionSPut(code));
-#endif
return static_cast<DexMemAccessType>(code - Instruction::SPUT);
}
constexpr DexMemAccessType AGetMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionAGet(code));
-#endif
return static_cast<DexMemAccessType>(code - Instruction::AGET);
}
constexpr DexMemAccessType APutMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionAPut(code));
-#endif
return static_cast<DexMemAccessType>(code - Instruction::APUT);
}
constexpr DexMemAccessType IGetOrIPutMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionIGetOrIPut(code));
-#endif
return (code >= Instruction::IPUT) ? IPutMemAccessType(code) : IGetMemAccessType(code);
}
-static inline DexMemAccessType IGetQuickOrIPutQuickMemAccessType(Instruction::Code code) {
+inline DexMemAccessType IGetQuickOrIPutQuickMemAccessType(Instruction::Code code) {
DCHECK(IsInstructionIGetQuickOrIPutQuick(code));
switch (code) {
case Instruction::IGET_QUICK: case Instruction::IPUT_QUICK:
@@ -225,16 +205,12 @@
}
constexpr DexMemAccessType SGetOrSPutMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionSGetOrSPut(code));
-#endif
return (code >= Instruction::SPUT) ? SPutMemAccessType(code) : SGetMemAccessType(code);
}
constexpr DexMemAccessType AGetOrAPutMemAccessType(Instruction::Code code) {
-#if __cplusplus >= 201402 // C++14 allows the DCHECK() in constexpr functions.
DCHECK(IsInstructionAGetOrAPut(code));
-#endif
return (code >= Instruction::APUT) ? APutMemAccessType(code) : AGetMemAccessType(code);
}