glsl: Avoid aliasing violations.
authorMatt Turner <mattst88@gmail.com>
Thu, 26 May 2016 22:53:00 +0000 (15:53 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 26 Jul 2016 19:12:27 +0000 (12:12 -0700)
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/compiler/glsl/ir_constant_expression.cpp
src/compiler/glsl/link_uniform_initializers.cpp

index ea50087f4c02c8c9b8cdc2ad1b41ebbf51d4ac7e..6329acde2b63b1e981db360e7614d4fc039844be 100644 (file)
@@ -1573,18 +1573,13 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
          data.f[c] = CLAMP(op[0]->value.f[c], 0.0f, 1.0f);
       }
       break;
-   case ir_unop_pack_double_2x32: {
+   case ir_unop_pack_double_2x32:
       /* XXX needs to be checked on big-endian */
-      uint64_t temp;
-      temp = (uint64_t)op[0]->value.u[0] | ((uint64_t)op[0]->value.u[1] << 32);
-      data.d[0] = *(double *)&temp;
-
+      memcpy(&data.d[0], &op[0]->value.u[0], sizeof(double));
       break;
-   }
    case ir_unop_unpack_double_2x32:
       /* XXX needs to be checked on big-endian */
-      data.u[0] = *(uint32_t *)&op[0]->value.d[0];
-      data.u[1] = *((uint32_t *)&op[0]->value.d[0] + 1);
+      memcpy(&data.u[0], &op[0]->value.d[0], sizeof(double));
       break;
 
    case ir_triop_bitfield_extract: {
index effbb6aea0c959c6432ca5decaf8076356dce277..17660a75741dc90e438826a4f836b389953543e9 100644 (file)
@@ -65,8 +65,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
         break;
       case GLSL_TYPE_DOUBLE:
          /* XXX need to check on big-endian */
-         storage[i * 2].u = *(uint32_t *)&val->value.d[i];
-         storage[i * 2 + 1].u = *(((uint32_t *)&val->value.d[i]) + 1);
+         memcpy(&storage[i * 2].u, &val->value.d[i], sizeof(double));
          break;
       case GLSL_TYPE_BOOL:
         storage[i].b = val->value.b[i] ? boolean_true : 0;