From f7eaed5286974984ba5f9e3189d8f49d03e99f81 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 12 May 2022 15:59:20 +0200 Subject: BASELINE: Update Chromium to 100.0.4896.167 Change-Id: I98cbeb5d7543d966ffe04d8cefded0c493a11333 Reviewed-by: Allan Sandfeld Jensen --- chromium/base/numerics/checked_math.h | 4 +-- chromium/base/numerics/checked_math_impl.h | 13 ++++----- chromium/base/numerics/clamped_math.h | 6 ++-- chromium/base/numerics/clamped_math_impl.h | 10 +++---- chromium/base/numerics/ranges.h | 19 +----------- chromium/base/numerics/safe_conversions.h | 3 +- chromium/base/numerics/safe_conversions_arm_impl.h | 4 +-- chromium/base/numerics/safe_conversions_impl.h | 34 +++++++--------------- chromium/base/numerics/safe_math_arm_impl.h | 14 +++++---- chromium/base/numerics/safe_math_shared_impl.h | 2 +- 10 files changed, 38 insertions(+), 71 deletions(-) (limited to 'chromium/base/numerics') diff --git a/chromium/base/numerics/checked_math.h b/chromium/base/numerics/checked_math.h index a2268c0d3b9..bbc575c457b 100644 --- a/chromium/base/numerics/checked_math.h +++ b/chromium/base/numerics/checked_math.h @@ -38,7 +38,7 @@ class CheckedNumeric { template constexpr CheckedNumeric(Src value) // NOLINT(runtime/explicit) : state_(value) { - static_assert(std::is_arithmetic::value, "Argument must be numeric."); + static_assert(UnderlyingType::is_numeric, "Argument must be numeric."); } // This is not an explicit constructor because we want a seamless conversion @@ -139,7 +139,7 @@ class CheckedNumeric { constexpr CheckedNumeric operator-() const { // Use an optimized code path for a known run-time variable. - if (!MustTreatAsConstexpr(state_.value()) && std::is_signed::value && + if (!IsConstantEvaluated() && std::is_signed::value && std::is_floating_point::value) { return FastRuntimeNegate(); } diff --git a/chromium/base/numerics/checked_math_impl.h b/chromium/base/numerics/checked_math_impl.h index 82495400554..1b83a0d059c 100644 --- a/chromium/base/numerics/checked_math_impl.h +++ b/chromium/base/numerics/checked_math_impl.h @@ -51,8 +51,7 @@ struct CheckedAddOp::type; template static constexpr bool Do(T x, U y, V* result) { - // TODO(jschuh) Make this "constexpr if" once we're C++17. - if (CheckedAddFastOp::is_supported) + if constexpr (CheckedAddFastOp::is_supported) return CheckedAddFastOp::Do(x, y, result); // Double the underlying type up to a full machine word. @@ -115,8 +114,7 @@ struct CheckedSubOp::type; template static constexpr bool Do(T x, U y, V* result) { - // TODO(jschuh) Make this "constexpr if" once we're C++17. - if (CheckedSubFastOp::is_supported) + if constexpr (CheckedSubFastOp::is_supported) return CheckedSubFastOp::Do(x, y, result); // Double the underlying type up to a full machine word. @@ -181,8 +179,7 @@ struct CheckedMulOp::type; template static constexpr bool Do(T x, U y, V* result) { - // TODO(jschuh) Make this "constexpr if" once we're C++17. - if (CheckedMulFastOp::is_supported) + if constexpr (CheckedMulFastOp::is_supported) return CheckedMulFastOp::Do(x, y, result); using Promotion = typename FastIntegerArithmeticPromotion::type; @@ -334,7 +331,7 @@ struct CheckedRshOp::value>::type> { using result_type = T; template - static bool Do(T x, U shift, V* result) { + static constexpr bool Do(T x, U shift, V* result) { // Use sign conversion to push negative values out of range. if (BASE_NUMERICS_UNLIKELY(as_unsigned(shift) >= IntegerBitsPlusSign::value)) { @@ -564,7 +561,7 @@ class CheckedNumericState { constexpr bool is_valid() const { // Written this way because std::isfinite is not reliably constexpr. - return MustTreatAsConstexpr(value_) + return IsConstantEvaluated() ? value_ <= std::numeric_limits::max() && value_ >= std::numeric_limits::lowest() : std::isfinite(value_); diff --git a/chromium/base/numerics/clamped_math.h b/chromium/base/numerics/clamped_math.h index e84d149d99d..20e2eb47150 100644 --- a/chromium/base/numerics/clamped_math.h +++ b/chromium/base/numerics/clamped_math.h @@ -38,7 +38,7 @@ class ClampedNumeric { template constexpr ClampedNumeric(Src value) // NOLINT(runtime/explicit) : value_(saturated_cast(value)) { - static_assert(std::is_arithmetic::value, "Argument must be numeric."); + static_assert(UnderlyingType::is_numeric, "Argument must be numeric."); } // This is not an explicit constructor because we want a seamless conversion @@ -178,8 +178,8 @@ class ClampedNumeric { // ClampedNumeric and POD arithmetic types. template struct Wrapper { - static constexpr Src value(Src value) { - return static_cast::type>(value); + static constexpr typename UnderlyingType::type value(Src value) { + return value; } }; }; diff --git a/chromium/base/numerics/clamped_math_impl.h b/chromium/base/numerics/clamped_math_impl.h index 303a7e945a1..061f8c42120 100644 --- a/chromium/base/numerics/clamped_math_impl.h +++ b/chromium/base/numerics/clamped_math_impl.h @@ -25,7 +25,7 @@ template ::value && std::is_signed::value>::type* = nullptr> constexpr T SaturatedNegWrapper(T value) { - return MustTreatAsConstexpr(value) || !ClampedNegFastOp::is_supported + return IsConstantEvaluated() || !ClampedNegFastOp::is_supported ? (NegateWrapper(value) != std::numeric_limits::lowest() ? NegateWrapper(value) : std::numeric_limits::max()) @@ -79,7 +79,7 @@ struct ClampedAddOp::type; template static constexpr V Do(T x, U y) { - if (ClampedAddFastOp::is_supported) + if (!IsConstantEvaluated() && ClampedAddFastOp::is_supported) return ClampedAddFastOp::template Do(x, y); static_assert(std::is_same::value || @@ -105,8 +105,7 @@ struct ClampedSubOp::type; template static constexpr V Do(T x, U y) { - // TODO(jschuh) Make this "constexpr if" once we're C++17. - if (ClampedSubFastOp::is_supported) + if (!IsConstantEvaluated() && ClampedSubFastOp::is_supported) return ClampedSubFastOp::template Do(x, y); static_assert(std::is_same::value || @@ -132,8 +131,7 @@ struct ClampedMulOp::type; template static constexpr V Do(T x, U y) { - // TODO(jschuh) Make this "constexpr if" once we're C++17. - if (ClampedMulFastOp::is_supported) + if (!IsConstantEvaluated() && ClampedMulFastOp::is_supported) return ClampedMulFastOp::template Do(x, y); V result = {}; diff --git a/chromium/base/numerics/ranges.h b/chromium/base/numerics/ranges.h index 58deb6feecb..ebe1302b3d5 100644 --- a/chromium/base/numerics/ranges.h +++ b/chromium/base/numerics/ranges.h @@ -5,28 +5,11 @@ #ifndef BASE_NUMERICS_RANGES_H_ #define BASE_NUMERICS_RANGES_H_ -#include #include +#include namespace base { -// DO NOT USE THIS FUNCTION. IT IS DUE TO BE REMOVED. https://crbug.com/1231569 -// Please use base::clamp() from base/cxx17_backports.h instead. -// -// This function, unlike base::clamp(), does not check if `min` is greater than -// `max`, and returns a bogus answer if it is. Please migrate all code that -// calls this function to use base::clamp() instead. -// -// If, for some reason the broken behavior is required, please re-create this -// min/max nesting inline in the host code and explain with a comment why it -// is needed. -template -constexpr const T& BrokenClampThatShouldNotBeUsed(const T& value, - const T& min, - const T& max) { - return std::min(std::max(value, min), max); -} - template constexpr bool IsApproximatelyEqual(T lhs, T rhs, T tolerance) { static_assert(std::is_arithmetic::value, "Argument must be arithmetic"); diff --git a/chromium/base/numerics/safe_conversions.h b/chromium/base/numerics/safe_conversions.h index 2bc8dd7c1bc..f41742c5f6e 100644 --- a/chromium/base/numerics/safe_conversions.h +++ b/chromium/base/numerics/safe_conversions.h @@ -204,8 +204,7 @@ template constexpr Dst saturated_cast(Src value) { using SrcType = typename UnderlyingType::type; - return !IsCompileTimeConstant(value) && - SaturateFastOp::is_supported && + return !IsConstantEvaluated() && SaturateFastOp::is_supported && std::is_same, SaturationDefaultLimits>::value ? SaturateFastOp::Do(static_cast(value)) diff --git a/chromium/base/numerics/safe_conversions_arm_impl.h b/chromium/base/numerics/safe_conversions_arm_impl.h index cf31072b9b8..afc84df2dfd 100644 --- a/chromium/base/numerics/safe_conversions_arm_impl.h +++ b/chromium/base/numerics/safe_conversions_arm_impl.h @@ -18,8 +18,8 @@ namespace internal { template struct SaturateFastAsmOp { static constexpr bool is_supported = - std::is_signed::value && std::is_integral::value && - std::is_integral::value && + kEnableAsmCode && std::is_signed::value && + std::is_integral::value && std::is_integral::value && IntegerBitsPlusSign::value <= IntegerBitsPlusSign::value && IntegerBitsPlusSign::value <= IntegerBitsPlusSign::value && !IsTypeInRangeForNumericType::value; diff --git a/chromium/base/numerics/safe_conversions_impl.h b/chromium/base/numerics/safe_conversions_impl.h index c1f8f7c13d0..d45f14f1f33 100644 --- a/chromium/base/numerics/safe_conversions_impl.h +++ b/chromium/base/numerics/safe_conversions_impl.h @@ -85,30 +85,18 @@ constexpr typename std::make_unsigned::type SafeUnsignedAbs(T value) { : static_cast(value); } -// This allows us to switch paths on known compile-time constants. -#if defined(__clang__) || defined(__GNUC__) -constexpr bool CanDetectCompileTimeConstant() { - return true; -} -template -constexpr bool IsCompileTimeConstant(const T v) { - return __builtin_constant_p(v); -} +// TODO(jschuh): Switch to std::is_constant_evaluated() once C++20 is supported. +// Alternately, the usage could be restructured for "consteval if" in C++23. +#define IsConstantEvaluated() (__builtin_is_constant_evaluated()) + +// TODO(jschuh): Debug builds don't reliably propagate constants, so we restrict +// some accelerated runtime paths to release builds until this can be forced +// with consteval support in C++20 or C++23. +#if defined(NDEBUG) +constexpr bool kEnableAsmCode = true; #else -constexpr bool CanDetectCompileTimeConstant() { - return false; -} -template -constexpr bool IsCompileTimeConstant(const T) { - return false; -} +constexpr bool kEnableAsmCode = false; #endif -template -constexpr bool MustTreatAsConstexpr(const T v) { - // Either we can't detect a compile-time constant, and must always use the - // constexpr path, or we know we have a compile-time constant. - return !CanDetectCompileTimeConstant() || IsCompileTimeConstant(v); -} // Forces a crash, like a CHECK(false). Used for numeric boundary errors. // Also used in a constexpr template to trigger a compilation failure on @@ -193,7 +181,7 @@ class RangeCheck { public: constexpr RangeCheck(bool is_in_lower_bound, bool is_in_upper_bound) : is_underflow_(!is_in_lower_bound), is_overflow_(!is_in_upper_bound) {} - constexpr RangeCheck() : is_underflow_(0), is_overflow_(0) {} + constexpr RangeCheck() : is_underflow_(false), is_overflow_(false) {} constexpr bool IsValid() const { return !is_overflow_ && !is_underflow_; } constexpr bool IsInvalid() const { return is_overflow_ && is_underflow_; } constexpr bool IsOverflow() const { return is_overflow_ && !is_underflow_; } diff --git a/chromium/base/numerics/safe_math_arm_impl.h b/chromium/base/numerics/safe_math_arm_impl.h index dcf33a3d199..67a84cf9428 100644 --- a/chromium/base/numerics/safe_math_arm_impl.h +++ b/chromium/base/numerics/safe_math_arm_impl.h @@ -16,9 +16,10 @@ namespace internal { template struct CheckedMulFastAsmOp { static const bool is_supported = - FastIntegerArithmeticPromotion::is_contained; + kEnableAsmCode && FastIntegerArithmeticPromotion::is_contained; - // The following is much more efficient than the Clang and GCC builtins for + // The following is not an assembler routine and is thus constexpr safe, it + // just emits much more efficient code than the Clang and GCC builtins for // performing overflow-checked multiplication when a twice wider type is // available. The below compiles down to 2-3 instructions, depending on the // width of the types in use. @@ -30,7 +31,7 @@ struct CheckedMulFastAsmOp { // asr r2, r1, #16 // cmp r2, r1, asr #15 template - __attribute__((always_inline)) static bool Do(T x, U y, V* result) { + static constexpr bool Do(T x, U y, V* result) { using Promotion = typename FastIntegerArithmeticPromotion::type; Promotion presult; @@ -45,7 +46,7 @@ struct CheckedMulFastAsmOp { template struct ClampedAddFastAsmOp { static const bool is_supported = - BigEnoughPromotion::is_contained && + kEnableAsmCode && BigEnoughPromotion::is_contained && IsTypeInRangeForNumericType< int32_t, typename BigEnoughPromotion::type>::value; @@ -71,7 +72,7 @@ struct ClampedAddFastAsmOp { template struct ClampedSubFastAsmOp { static const bool is_supported = - BigEnoughPromotion::is_contained && + kEnableAsmCode && BigEnoughPromotion::is_contained && IsTypeInRangeForNumericType< int32_t, typename BigEnoughPromotion::type>::value; @@ -96,7 +97,8 @@ struct ClampedSubFastAsmOp { template struct ClampedMulFastAsmOp { - static const bool is_supported = CheckedMulFastAsmOp::is_supported; + static const bool is_supported = + kEnableAsmCode && CheckedMulFastAsmOp::is_supported; template __attribute__((always_inline)) static V Do(T x, U y) { diff --git a/chromium/base/numerics/safe_math_shared_impl.h b/chromium/base/numerics/safe_math_shared_impl.h index f2e5e7ef470..ba91016758e 100644 --- a/chromium/base/numerics/safe_math_shared_impl.h +++ b/chromium/base/numerics/safe_math_shared_impl.h @@ -18,7 +18,7 @@ #include "base/numerics/safe_conversions.h" #include "build/build_config.h" -#if defined(OS_ASMJS) +#if BUILDFLAG(IS_ASMJS) // Optimized safe math instructions are incompatible with asmjs. #define BASE_HAS_OPTIMIZED_SAFE_MATH (0) // Where available use builtin math overflow support on Clang and GCC. -- cgit v1.2.1