[Mesa-dev] [PATCH 10/17] glsl/tests: Fix strict aliasing warning about int64/double.

Eric Anholt eric at anholt.net
Sat Feb 10 16:33:03 UTC 2018


Cc: Rhys Kidd <rhyskidd at gmail.com>
Fixes: 4bf986274728 ("glsl/tests: Add UINT64 and INT64 types")
---
 .../glsl/tests/uniform_initializer_utils.cpp       | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/compiler/glsl/tests/uniform_initializer_utils.cpp b/src/compiler/glsl/tests/uniform_initializer_utils.cpp
index 701c8ef4d091..0d7fa26752fd 100644
--- a/src/compiler/glsl/tests/uniform_initializer_utils.cpp
+++ b/src/compiler/glsl/tests/uniform_initializer_utils.cpp
@@ -204,6 +204,22 @@ generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
    val = new(mem_ctx) ir_constant(array_type, &values_for_array);
 }
 
+static uint64_t
+uint64_storage(union gl_constant_value *storage)
+{
+   uint64_t val;
+   memcpy(&val, &storage->i, sizeof(uint64_t));
+   return val;
+}
+
+static uint64_t
+double_storage(union gl_constant_value *storage)
+{
+   double val;
+   memcpy(&val, &storage->i, sizeof(double));
+   return val;
+}
+
 /**
  * Verify that the data stored for the uniform matches the initializer
  *
@@ -252,13 +268,13 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size,
 	    EXPECT_EQ(val->value.b[i] ? boolean_true : 0, storage[i].i);
 	    break;
 	 case GLSL_TYPE_DOUBLE:
-	    EXPECT_EQ(val->value.d[i], *(double *)&storage[i*2].i);
+	    EXPECT_EQ(val->value.d[i], double_storage(&storage[i*2]));
 	    break;
 	 case GLSL_TYPE_UINT64:
-	    EXPECT_EQ(val->value.u64[i], *(uint64_t *)&storage[i*2].i);
+            EXPECT_EQ(val->value.u64[i], uint64_storage(&storage[i*2]));
 	    break;
 	 case GLSL_TYPE_INT64:
-	    EXPECT_EQ(val->value.i64[i], *(int64_t *)&storage[i*2].i);
+	    EXPECT_EQ(val->value.i64[i], uint64_storage(&storage[i*2]));
 	    break;
          case GLSL_TYPE_ATOMIC_UINT:
 	 case GLSL_TYPE_STRUCT:
-- 
2.15.0



More information about the mesa-dev mailing list