glsl/tests: Fix strict aliasing warning about int64/double.
authorEric Anholt <eric@anholt.net>
Sat, 10 Feb 2018 11:01:20 +0000 (11:01 +0000)
committerEric Anholt <eric@anholt.net>
Mon, 12 Feb 2018 20:48:43 +0000 (20:48 +0000)
Fixes: 4bf986274728 ("glsl/tests: Add UINT64 and INT64 types")
Reviewed-by: Rhys Kidd <rhyskidd@gmail.com>
src/compiler/glsl/tests/uniform_initializer_utils.cpp

index c5502b63269799e69ed962e44ab60f4f8f845cdd..a1c68c8272eb9cf712973f2786d4c0b321ec57a1 100644 (file)
@@ -198,6 +198,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
  *
@@ -246,13 +262,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: