From 6f6bfe146f119a31145a0d067c7b13d274d06ed5 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Fri, 25 Jun 2021 10:08:16 -0700 Subject: [PATCH] Reland "Fix -Wimplicit-int-float-conversions." This is a reland of edab8730718cf92d4262616e66e57202fdcfa8a8 It was speculatively reverted but the issue turned out to just be slow tests. Original change's description: > Fix -Wimplicit-int-float-conversions. > > Bug: chromium:989932 > Change-Id: Ief917b023cb079f5ff87dc8963d74f225d074d7a > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2989096 > Reviewed-by: Bill Budge > Reviewed-by: Sigurd Schneider > Auto-Submit: Peter Kasting > Commit-Queue: Peter Kasting > Cr-Commit-Position: refs/heads/master@{#75413} Bug: chromium:989932 Change-Id: Iec8ac8ee32705c6a699a2df2f292ffe07cde99f7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2994802 Reviewed-by: Bill Budge Reviewed-by: Sigurd Schneider Commit-Queue: Bill Budge Cr-Commit-Position: refs/heads/master@{#75443} --- src/compiler/representation-change.cc | 4 ++-- src/objects/elements.cc | 13 +++++++------ src/runtime/runtime-array.cc | 2 +- src/wasm/wasm-external-refs.cc | 4 ++-- test/cctest/test-api.h | 4 ++-- .../unittests/heap/gc-idle-time-handler-unittest.cc | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/compiler/representation-change.cc b/src/compiler/representation-change.cc index 750bc1fd56..f1aa47b233 100644 --- a/src/compiler/representation-change.cc +++ b/src/compiler/representation-change.cc @@ -7,6 +7,7 @@ #include #include "src/base/bits.h" +#include "src/base/safe_conversions.h" #include "src/codegen/code-factory.h" #include "src/compiler/js-heap-broker.h" #include "src/compiler/machine-operator.h" @@ -1090,8 +1091,7 @@ Node* RepresentationChanger::GetWord64RepresentationFor( case IrOpcode::kNumberConstant: { if (use_info.type_check() != TypeCheckKind::kBigInt) { double const fv = OpParameter(node->op()); - using limits = std::numeric_limits; - if (fv <= limits::max() && fv >= limits::min()) { + if (base::IsValueInRangeForNumericType(fv)) { int64_t const iv = static_cast(fv); if (static_cast(iv) == fv) { return jsgraph()->Int64Constant(iv); diff --git a/src/objects/elements.cc b/src/objects/elements.cc index 877115ac9f..dd137aab55 100644 --- a/src/objects/elements.cc +++ b/src/objects/elements.cc @@ -5,6 +5,7 @@ #include "src/objects/elements.h" #include "src/base/atomicops.h" +#include "src/base/safe_conversions.h" #include "src/common/message-template.h" #include "src/execution/arguments.h" #include "src/execution/frames.h" @@ -3367,8 +3368,8 @@ class TypedElementsAccessor } return Just(false); } - } else if (search_value < std::numeric_limits::lowest() || - search_value > std::numeric_limits::max()) { + } else if (!base::IsValueInRangeForNumericType( + search_value)) { // Return false if value can't be represented in this space. return Just(false); } @@ -3414,8 +3415,8 @@ class TypedElementsAccessor if (std::isnan(search_value)) { return Just(-1); } - } else if (search_value < std::numeric_limits::lowest() || - search_value > std::numeric_limits::max()) { + } else if (!base::IsValueInRangeForNumericType( + search_value)) { // Return false if value can't be represented in this ElementsKind. return Just(-1); } @@ -3467,8 +3468,8 @@ class TypedElementsAccessor // Strict Equality Comparison of NaN is always false. return Just(-1); } - } else if (search_value < std::numeric_limits::lowest() || - search_value > std::numeric_limits::max()) { + } else if (!base::IsValueInRangeForNumericType( + search_value)) { // Return -1 if value can't be represented in this ElementsKind. return Just(-1); } diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc index 4114431b89..fbf0dfe508 100644 --- a/src/runtime/runtime-array.cc +++ b/src/runtime/runtime-array.cc @@ -374,7 +374,7 @@ RUNTIME_FUNCTION(Runtime_ArrayIndexOf) { if (fp > len) return Smi::FromInt(-1); if (V8_LIKELY(fp >= static_cast(std::numeric_limits::min()))) { - DCHECK(fp < std::numeric_limits::max()); + DCHECK(fp < static_cast(std::numeric_limits::max())); start_from = static_cast(fp); } else { start_from = std::numeric_limits::min(); diff --git a/src/wasm/wasm-external-refs.cc b/src/wasm/wasm-external-refs.cc index f3d900b79a..101d563876 100644 --- a/src/wasm/wasm-external-refs.cc +++ b/src/wasm/wasm-external-refs.cc @@ -238,7 +238,7 @@ void float32_to_uint64_sat_wrapper(Address data) { WriteUnalignedValue(data, static_cast(input)); return; } - if (input >= std::numeric_limits::max()) { + if (input >= static_cast(std::numeric_limits::max())) { WriteUnalignedValue(data, std::numeric_limits::max()); return; } @@ -268,7 +268,7 @@ void float64_to_uint64_sat_wrapper(Address data) { WriteUnalignedValue(data, static_cast(input)); return; } - if (input >= std::numeric_limits::max()) { + if (input >= static_cast(std::numeric_limits::max())) { WriteUnalignedValue(data, std::numeric_limits::max()); return; } diff --git a/test/cctest/test-api.h b/test/cctest/test-api.h index df57ea6048..56128236db 100644 --- a/test/cctest/test-api.h +++ b/test/cctest/test-api.h @@ -95,7 +95,7 @@ struct ConvertJSValue { constexpr uint64_t kMaxULL = std::numeric_limits::max(); // -2^{64} < fmod_value < 2^{64}. - double fmod_value = fmod(result, kMaxULL + 1.0); + double fmod_value = fmod(result, static_cast(kMaxULL)); if (fmod_value >= 0) { if (fmod_value < pow(2, 63)) { // 0 <= fmod_value < 2^{63}. @@ -133,7 +133,7 @@ struct ConvertJSValue { constexpr uint64_t kMaxULL = std::numeric_limits::max(); // -2^{64} < fmod_value < 2^{64}. - double fmod_value = fmod(result, kMaxULL + 1.0); + double fmod_value = fmod(result, static_cast(kMaxULL)); if (fmod_value >= 0) { return v8::Just(static_cast(fmod_value)); } diff --git a/test/unittests/heap/gc-idle-time-handler-unittest.cc b/test/unittests/heap/gc-idle-time-handler-unittest.cc index 55b8718675..8aba018393 100644 --- a/test/unittests/heap/gc-idle-time-handler-unittest.cc +++ b/test/unittests/heap/gc-idle-time-handler-unittest.cc @@ -57,7 +57,7 @@ TEST(GCIdleTimeHandler, EstimateMarkingStepSizeNonZero) { TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow1) { size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( - 10, std::numeric_limits::max()); + 10, static_cast(std::numeric_limits::max())); EXPECT_EQ(static_cast(GCIdleTimeHandler::kMaximumMarkingStepSize), step_size); } @@ -65,7 +65,7 @@ TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow1) { TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow2) { size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( - std::numeric_limits::max(), 10); + static_cast(std::numeric_limits::max()), 10); EXPECT_EQ(static_cast(GCIdleTimeHandler::kMaximumMarkingStepSize), step_size); }