aboutsummaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorPablo Marquez Tello <pablo.tello@arm.com>2021-03-24 17:50:19 +0000
committerPablo Marquez Tello <pablo.tello@arm.com>2021-03-25 13:25:54 +0000
commitf73db971cfc36c82c1aa6409257a11f987aaea92 (patch)
tree3d2fd738415e057801281d44a49f4b9e15388aba /support
parente7254a09c54f09413ac3b23d4997089ebdbc4387 (diff)
downloadComputeLibrary-f73db971cfc36c82c1aa6409257a11f987aaea92.tar.gz
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 <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5318 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Manuel Bottini <manuel.bottini@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'support')
-rw-r--r--support/Bfloat16.h11
1 files changed, 6 insertions, 5 deletions
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 <cstdint>
+#include <cstring>
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<const float *>(&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 */