Commit 83bf6629 authored by Nico Hartmann's avatar Nico Hartmann Committed by V8 LUCI CQ

[Torque] Fix compile error in integer-literal.h

Bug: v8:7793
Change-Id: I88e6ea24909ba1dde8cada90d7b195b6f6ecc783
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3400958Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Auto-Submit: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78678}
parent 069d62eb
...@@ -12,6 +12,15 @@ ...@@ -12,6 +12,15 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
template <typename T, bool Safe>
struct Shifter {
static constexpr T shift_right(T value, T shift) { return value >> shift; }
};
template <typename T>
struct Shifter<T, false> {
static constexpr T shift_right(T value, T shift) { return T(0); }
};
class IntegerLiteral { class IntegerLiteral {
public: public:
using digit_t = bigint::digit_t; using digit_t = bigint::digit_t;
...@@ -100,19 +109,20 @@ class IntegerLiteral { ...@@ -100,19 +109,20 @@ class IntegerLiteral {
explicit IntegerLiteral(T value, bool perform_dcheck) : sign_(false) { explicit IntegerLiteral(T value, bool perform_dcheck) : sign_(false) {
static_assert(std::is_integral<T>::value, "Integral type required"); static_assert(std::is_integral<T>::value, "Integral type required");
if (value == T(0)) return; if (value == T(0)) return;
auto absolute = static_cast<typename std::make_unsigned<T>::type>(value); using unsigned_t = std::make_unsigned_t<T>;
auto absolute = static_cast<unsigned_t>(value);
if (value < T(0)) { if (value < T(0)) {
sign_ = true; sign_ = true;
absolute = (~absolute) + 1; absolute = (~absolute) + 1;
} }
if (sizeof(absolute) <= sizeof(digit_t)) { do {
digits_.push_back(absolute); digits_.push_back(static_cast<digit_t>(absolute));
} else { absolute =
do { Shifter<unsigned_t, (sizeof(absolute) >
digits_.push_back(static_cast<digit_t>(absolute)); sizeof(digit_t))>::shift_right(absolute,
absolute >>= sizeof(digit_t) * kBitsPerByte; sizeof(digit_t) *
} while (absolute != 0); kBitsPerByte);
} } while (absolute != 0);
if (perform_dcheck) DCHECK_EQ(To<T>(), value); if (perform_dcheck) DCHECK_EQ(To<T>(), value);
} }
......
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