aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-graphics/vk-gl-cts/files/0001-Workaround-for-GCC-11-uninit-variable-warnings-946.patch
blob: 6c87cad0a664574f24c3be7cbfd260fe45de0779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
From 9cd614dd5481a4fdf552effac4820f51a10092c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mika=20V=C3=A4in=C3=B6l=C3=A4?=
 <33728696+mvainola@users.noreply.github.com>
Date: Wed, 7 Apr 2021 13:12:17 +0300
Subject: [PATCH] Workaround for GCC 11 uninit variable warnings (#946)

Building Amber with GCC 11.0.1 produces some uninitialized variable
warnings. This commit works around them by replacing
reinterpret_cast with memcpy when type punning unsigned integers to
floats.

Upstream-Status: Backport [https://github.com/google/amber/commit/aa69a0ac23ea7f68dd32bbef210546a5d84c1734]
---
 src/float16_helper.cc | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/float16_helper.cc b/src/float16_helper.cc
index 617bd72..5cb35e7 100644
--- a/src/float16_helper.cc
+++ b/src/float16_helper.cc
@@ -15,6 +15,7 @@
 #include "src/float16_helper.h"
 
 #include <cassert>
+#include <cstring>
 
 // Float10
 // | 9 8 7 6 5 | 4 3 2 1 0 |
@@ -75,8 +76,11 @@ float HexFloat16ToFloat(const uint8_t* value) {
   }
 
   uint32_t hex = sign | exponent | mantissa;
-  float* hex_float = reinterpret_cast<float*>(&hex);
-  return *hex_float;
+  float hex_float;
+  static_assert((sizeof(uint32_t) == sizeof(float)),
+                "sizeof(uint32_t) != sizeof(float)");
+  memcpy(&hex_float, &hex, sizeof(float));
+  return hex_float;
 }
 
 // Convert float |value| whose size is 11 bits to 32 bits float
@@ -89,8 +93,11 @@ float HexFloat11ToFloat(const uint8_t* value) {
   uint32_t mantissa = (static_cast<uint32_t>(value[0]) & 0x3f) << 17U;
 
   uint32_t hex = exponent | mantissa;
-  float* hex_float = reinterpret_cast<float*>(&hex);
-  return *hex_float;
+  float hex_float;
+  static_assert((sizeof(uint32_t) == sizeof(float)),
+                "sizeof(uint32_t) != sizeof(float)");
+  memcpy(&hex_float, &hex, sizeof(float));
+  return hex_float;
 }
 
 // Convert float |value| whose size is 10 bits to 32 bits float
@@ -103,8 +110,11 @@ float HexFloat10ToFloat(const uint8_t* value) {
   uint32_t mantissa = (static_cast<uint32_t>(value[0]) & 0x1f) << 18U;
 
   uint32_t hex = exponent | mantissa;
-  float* hex_float = reinterpret_cast<float*>(&hex);
-  return *hex_float;
+  float hex_float;
+  static_assert((sizeof(uint32_t) == sizeof(float)),
+                "sizeof(uint32_t) != sizeof(float)");
+  memcpy(&hex_float, &hex, sizeof(float));
+  return hex_float;
 }
 
 }  // namespace
-- 
2.31.1