Skip to content

Commit 6b8be71

Browse files
Fznamznonbader
authored andcommitted
[SYCL] Fix warning in half implementation
There was strict-aliasing rules violation. It could produce undefined behaviour. Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent dba5f18 commit 6b8be71

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sycl/source/half_type.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// This is included to enable __builtin_expect()
1111
#include <CL/sycl/detail/platform_util.hpp>
1212
#include <iostream>
13+
#include <cstring>
1314

1415
namespace cl {
1516
namespace sycl {
@@ -105,7 +106,9 @@ static float half2Float(const uint16_t &Val) {
105106
Bits |= (Exp32 << 23);
106107
Bits |= Frac32;
107108

108-
return *reinterpret_cast<float *>(&Bits);
109+
float Result;
110+
std::memcpy(&Result, &Bits, sizeof(Result));
111+
return Result;
109112
}
110113

111114
std::ostream &operator<<(std::ostream &O, const half_impl::half &Val) {

0 commit comments

Comments
 (0)