From f73db971cfc36c82c1aa6409257a11f987aaea92 Mon Sep 17 00:00:00 2001 From: Pablo Marquez Tello Date: Wed, 24 Mar 2021 17:50:19 +0000 Subject: bf16_to_float: Fix strict aliasing violation * This function was accessing a uint32_t with a pointer to float which violates the strict aliasing rules. With GCC 11, this leads to a -Wuninitialized warning, which causes the build to fail. * This change uses memcpy instead of type punning which fixes the strict aliasing violation, thereby fixing the build with GCC 11. * Resolves MLCE-420 Change-Id: I9fda5f1e68ac68490b244bd40380910adae00bf3 Signed-off-by: Pablo Marquez Tello Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5318 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Manuel Bottini Reviewed-by: Georgios Pinitas --- support/Bfloat16.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'support') diff --git a/support/Bfloat16.h b/support/Bfloat16.h index d57d8ce9ee..173f2d16e2 100644 --- a/support/Bfloat16.h +++ b/support/Bfloat16.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Arm Limited. + * Copyright (c) 2020-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ #define ARM_COMPUTE_BFLOAT16_H #include +#include namespace arm_compute { @@ -70,9 +71,9 @@ inline uint16_t float_to_bf16(const float v) inline float bf16_to_float(const uint16_t &v) { const uint32_t lv = (v << 16); - const float *fp = reinterpret_cast(&lv); - - return *fp; + float fp; + memcpy(&fp, &lv, sizeof(lv)); + return fp; } } @@ -137,4 +138,4 @@ private: uint16_t value; }; } // namespace arm_compute -#endif /* ARM_COMPUTE_BFLOAT16_H */ \ No newline at end of file +#endif /* ARM_COMPUTE_BFLOAT16_H */ -- cgit v1.2.1