diff options
author | 2019-10-16 10:02:23 -0700 | |
---|---|---|
committer | 2019-10-17 13:26:49 +0000 | |
commit | 706e778ef7a84ddfef82e8e2e43f852960849935 (patch) | |
tree | 46a213bcc6926956298275629aa2b42eeebc0ed1 /compiler | |
parent | 352482c000830755405f5da3624891ff4690a36a (diff) |
[art] fix -Wimplicit-int-float-conversion
kPrimIntMax and kPrimLongMax are too large in value to be precisely
represented by IEEE 754 single and double precision, respectively.
The code in question is clamping the `value` to the above kConstants.
In this case, the imprecision doesn't result in logical errors. Accept
the imprecision via explicit cast.
Fixes:
art/compiler/optimizing/nodes.cc:1597:22: error: implicit conversion
from 'const int32_t' (aka 'const int') to 'float' changes value from
2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion]
if (value >= kPrimIntMax)
~~ ^~~~~~~~~~~
art/compiler/optimizing/nodes.cc:1605:22: error: implicit conversion
from 'const int64_t' (aka 'const long') to 'float' changes value from
9223372036854775807 to 9223372036854775808
[-Werror,-Wimplicit-int-float-conversion]
if (value >= kPrimLongMax)
~~ ^~~~~~~~~~~~
art/compiler/optimizing/nodes.cc:1629:22: error: implicit conversion
from 'const int64_t' (aka 'const long') to 'double' changes value from
9223372036854775807 to 9223372036854775808
[-Werror,-Wimplicit-int-float-conversion]
if (value >= kPrimLongMax)
~~ ^~~~~~~~~~~~
Bug: 139945549
Test: mm
Change-Id: I60582c13cfaceb6c6b217e13d7e9bd04d94874fe
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/optimizing/nodes.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 1940d55a9d..810871c18f 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -1594,7 +1594,7 @@ HConstant* HTypeConversion::TryStaticEvaluation() const { case DataType::Type::kInt32: if (std::isnan(value)) return graph->GetIntConstant(0, GetDexPc()); - if (value >= kPrimIntMax) + if (value >= static_cast<float>(kPrimIntMax)) return graph->GetIntConstant(kPrimIntMax, GetDexPc()); if (value <= kPrimIntMin) return graph->GetIntConstant(kPrimIntMin, GetDexPc()); @@ -1602,7 +1602,7 @@ HConstant* HTypeConversion::TryStaticEvaluation() const { case DataType::Type::kInt64: if (std::isnan(value)) return graph->GetLongConstant(0, GetDexPc()); - if (value >= kPrimLongMax) + if (value >= static_cast<float>(kPrimLongMax)) return graph->GetLongConstant(kPrimLongMax, GetDexPc()); if (value <= kPrimLongMin) return graph->GetLongConstant(kPrimLongMin, GetDexPc()); @@ -1626,7 +1626,7 @@ HConstant* HTypeConversion::TryStaticEvaluation() const { case DataType::Type::kInt64: if (std::isnan(value)) return graph->GetLongConstant(0, GetDexPc()); - if (value >= kPrimLongMax) + if (value >= static_cast<double>(kPrimLongMax)) return graph->GetLongConstant(kPrimLongMax, GetDexPc()); if (value <= kPrimLongMin) return graph->GetLongConstant(kPrimLongMin, GetDexPc()); |