aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Bentham <matthew.bentham@arm.com>2021-07-05 15:45:25 +0100
committerSadik Armagan <sadik.armagan@arm.com>2021-07-16 14:39:09 +0000
commit94df84d1e4964f00fbeaa29a720ef1822ba033d6 (patch)
tree15487f86c06dd3a2e563030cb5c1ee68f41f0684
parentc013bc85f45add8c4bc8c7163316bbb90b37a15e (diff)
downloadarmnn-94df84d1e4964f00fbeaa29a720ef1822ba033d6.tar.gz
Avoid undefined behaviour in NumericCast unit test
Because the maximum value of an int32_t isn't exactly representable by a 32-bit float, casting it to a float produces a greater value, and then casting that back to an int32_t is undefined. (In tested implementations the cast saturates, so accidentally the correct result is returned). Using double for the intermediate value instead gives a high enough precision that this test case can be safely expressed. Silences warning from Undefioned Behaviour Sanitiser. Signed-off-by: Matthew Bentham <matthew.bentham@arm.com> Change-Id: I6fe3e89cb6ac695049c92f3b75aca0c14d0e14aa
-rw-r--r--src/armnn/test/UtilityTests.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/armnn/test/UtilityTests.cpp b/src/armnn/test/UtilityTests.cpp
index b3b6c3bb3d..7911fd2608 100644
--- a/src/armnn/test/UtilityTests.cpp
+++ b/src/armnn/test/UtilityTests.cpp
@@ -202,7 +202,7 @@ TEST_CASE("NumericCast")
CHECK_NOTHROW(numeric_cast<int8_t>(static_cast<float>(int8_max)));
CHECK_NOTHROW(numeric_cast<int16_t>(static_cast<float>(int16_max)));
- CHECK_NOTHROW(numeric_cast<int32_t>(static_cast<float>(int32_max)));
+ CHECK_NOTHROW(numeric_cast<int32_t>(static_cast<double>(int32_max)));
CHECK_THROWS_AS(numeric_cast<int8_t>(float_max), std::bad_cast);
CHECK_THROWS_AS(numeric_cast<int16_t>(float_max), std::bad_cast);