Commit 68e8621d authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

Use safe conversion helper to check conversion limits

This is similar to https://crrev.com/c/2466377, for all other checks for
numeric_limits found in the same file.

The check for float/double to uint32/uint64 doesn't seem to be
replaceable, due to this check:
https://source.chromium.org/chromium/chromium/src/+/master:v8/src/base/safe_conversions_impl.h;l=361;drc=c10c83c31ba0b774c3c05c73bb4894ba2495394b
We probably need something specific for converting to float/doubles.
I'll leave those as they are first.

Bug: v8:10933
Change-Id: I5ea95fd04caa7b5963bb3cb8e5870cd8e790fb19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2477039
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70665}
parent 402806e8
......@@ -180,12 +180,8 @@ void uint64_to_float64_wrapper(Address data) {
}
int32_t float32_to_int64_wrapper(Address data) {
// We use "<" here to check the upper bound because of rounding problems: With
// "<=" some inputs would be considered within int64 range which are actually
// not within int64 range.
float input = ReadUnalignedValue<float>(data);
if (input >= static_cast<float>(std::numeric_limits<int64_t>::min()) &&
input < static_cast<float>(std::numeric_limits<int64_t>::max())) {
if (base::IsValueInRangeForNumericType<int64_t>(input)) {
WriteUnalignedValue<int64_t>(data, static_cast<int64_t>(input));
return 1;
}
......@@ -229,11 +225,7 @@ int32_t float64_to_uint64_wrapper(Address data) {
void float32_to_int64_sat_wrapper(Address data) {
float input = ReadUnalignedValue<float>(data);
// We use "<" here to check the upper bound because of rounding problems: With
// "<=" some inputs would be considered within int64 range which are actually
// not within int64 range.
if (input < static_cast<float>(std::numeric_limits<int64_t>::max()) &&
input >= static_cast<float>(std::numeric_limits<int64_t>::min())) {
if (base::IsValueInRangeForNumericType<int64_t>(input)) {
WriteUnalignedValue<int64_t>(data, static_cast<int64_t>(input));
return;
}
......
......@@ -725,8 +725,7 @@ WASM_EXEC_TEST(I64SConvertF32) {
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
if (i < static_cast<float>(std::numeric_limits<int64_t>::max()) &&
i >= static_cast<float>(std::numeric_limits<int64_t>::min())) {
if (base::IsValueInRangeForNumericType<int64_t>(i)) {
CHECK_EQ(static_cast<int64_t>(i), r.Call(i));
} else {
CHECK_TRAP64(r.Call(i));
......@@ -739,8 +738,7 @@ WASM_EXEC_TEST(I64SConvertSatF32) {
BUILD(r, WASM_I64_SCONVERT_SAT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
int64_t expected;
if (i < static_cast<float>(std::numeric_limits<int64_t>::max()) &&
i >= static_cast<float>(std::numeric_limits<int64_t>::min())) {
if (base::IsValueInRangeForNumericType<int64_t>(i)) {
expected = static_cast<int64_t>(i);
} else if (std::isnan(i)) {
expected = static_cast<int64_t>(0);
......
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