From 94df84d1e4964f00fbeaa29a720ef1822ba033d6 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Mon, 5 Jul 2021 15:45:25 +0100 Subject: 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 Change-Id: I6fe3e89cb6ac695049c92f3b75aca0c14d0e14aa --- src/armnn/test/UtilityTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(static_cast(int8_max))); CHECK_NOTHROW(numeric_cast(static_cast(int16_max))); - CHECK_NOTHROW(numeric_cast(static_cast(int32_max))); + CHECK_NOTHROW(numeric_cast(static_cast(int32_max))); CHECK_THROWS_AS(numeric_cast(float_max), std::bad_cast); CHECK_THROWS_AS(numeric_cast(float_max), std::bad_cast); -- cgit v1.2.1