[Mesa-dev] [PATCH] mesa/uniform: fix strict aliasing issues with int64 code.

Timothy Arceri t_arceri at yahoo.com.au
Wed Feb 8 01:45:29 UTC 2017


On Wed, 2017-02-08 at 11:21 +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This fixes these like the double version does.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/mesa/main/uniform_query.cpp | 38 ++++++++++++++++++++++++++-----
> -------
>  1 file changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/src/mesa/main/uniform_query.cpp
> b/src/mesa/main/uniform_query.cpp
> index 418cfc9..f23da43 100644
> --- a/src/mesa/main/uniform_query.cpp
> +++ b/src/mesa/main/uniform_query.cpp
> @@ -506,20 +506,28 @@ _mesa_get_uniform(struct gl_context *ctx,
> GLuint program, GLint location,
>              case GLSL_TYPE_INT64:
>              case GLSL_TYPE_UINT64:
>                 switch (uni->type->base_type) {
> -               case GLSL_TYPE_UINT:
> -                  *(int64_t *)&dst[didx].u = (int64_t) src[sidx].u;
> +               case GLSL_TYPE_UINT: {
> +		  uint64_t tmp = src[sidx].u;

Please remove the tab here. Otherwise this and the st patch are:

Reviewed-by: Timothy Arceri <t_arceri at yahoo.com.au>

> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
>                    break;
> +               }
>                 case GLSL_TYPE_INT:
>                 case GLSL_TYPE_SAMPLER:
> -               case GLSL_TYPE_IMAGE:
> -                  *(int64_t *)&dst[didx].u = (int64_t) src[sidx].i;
> +               case GLSL_TYPE_IMAGE: {
> +                  int64_t tmp = src[sidx].i;
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
>                    break;
> -               case GLSL_TYPE_BOOL:
> -                  *(int64_t *)&dst[didx].u = src[sidx].i ? 1.0f :
> 0.0f;
> +               }
> +               case GLSL_TYPE_BOOL: {
> +                  int64_t tmp = src[sidx].i ? 1.0f : 0.0f;
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
>                    break;
> -               case GLSL_TYPE_FLOAT:
> -                  *(int64_t *)&dst[didx].u = (int64_t) src[sidx].f;
> +               }
> +               case GLSL_TYPE_FLOAT: {
> +                  int64_t tmp = src[sidx].f;
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
>                    break;
> +               }
>                 default:
>                    assert(!"Should not get here.");
>                    break;
> @@ -562,12 +570,18 @@ log_uniform(const void *values, enum
> glsl_base_type basicType,
>        case GLSL_TYPE_INT:
>  	 printf("%d ", v[i].i);
>  	 break;
> -      case GLSL_TYPE_UINT64:
> -         printf("%lu ", *(uint64_t* )&v[i * 2].u);
> +      case GLSL_TYPE_UINT64: {
> +         uint64_t tmp;
> +         memcpy(&tmp, &v[i * 2].u, sizeof(tmp));
> +         printf("%lu ", tmp);
>           break;
> -      case GLSL_TYPE_INT64:
> -         printf("%ld ", *(int64_t* )&v[i * 2].u);
> +      }
> +      case GLSL_TYPE_INT64: {
> +         int64_t tmp;
> +         memcpy(&tmp, &v[i * 2].u, sizeof(tmp));
> +         printf("%ld ", tmp);
>           break;
> +      }
>        case GLSL_TYPE_FLOAT:
>  	 printf("%g ", v[i].f);
>  	 break;


More information about the mesa-dev mailing list