From 81a28fb3e2a5b6bec282ecb421cf4bfcce01565d Mon Sep 17 00:00:00 2001 From: Vignesh Raman Date: Mon, 4 Sep 2023 08:54:04 +0530 Subject: [PATCH] Do explicit cast to suppress clang warnings Do explicit cast to suppress the below clang warnings, ../src/mesa/main/get.c:86:31: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] return ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : ../src/mesa/main/texparam.c:967:27: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) : ../src/mesa/main/texparam.c:2609:65: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] *params = LCLAMPF(obj->Sampler.Attrib.MinLod, INT_MIN, INT_MAX); ../src/mesa/main/texparam.c:2624:65: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] *params = LCLAMPF(obj->Sampler.Attrib.MaxLod, INT_MIN, INT_MAX); ../src/mesa/main/texparam.c:2648:72: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] *params = LCLAMPF(obj->Sampler.Attrib.MaxAnisotropy, INT_MIN, INT_MAX); ../src/mesa/main/texparam.c:2693:66: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] *params = LCLAMPF(obj->Sampler.Attrib.LodBias, INT_MIN, INT_MAX); ../src/gallium/drivers/freedreno/a3xx/fd3_emit.c:731:43: error: implicit conversion from 'unsigned int' to 'float' changes value from 4294967295 to 4294967296 [-Werror,-Wimplicit-const-int-float-conversion] OUT_RING(ring, (uint32_t)(zmin * 0xffffffff)); ../src/gallium/drivers/freedreno/a3xx/fd3_emit.c:732:43: error: implicit conversion from 'unsigned int' to 'float' changes value from 4294967295 to 4294967296 [-Werror,-Wimplicit-const-int-float-conversion] OUT_RING(ring, (uint32_t)(zmax * 0xffffffff)); ../src/nouveau/codegen/nv50_ir_peephole.cpp:1647:30: error: implicit conversion from 'unsigned int' to 'float' changes value from 4294967295 to 4294967296 [-Werror,-Wimplicit-const-int-float-conversion] CASE(TYPE_U32, u32, 0, UINT32_MAX, 0, INT32_MAX, 0, UINT32_MAX); ../src/nouveau/codegen/nv50_ir_peephole.cpp:1648:38: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] CASE(TYPE_S32, s32, INT32_MIN, INT32_MAX, INT32_MIN, INT32_MAX, 0, INT32_MAX); ../src/gallium/drivers/radeonsi/si_nir_lower_vs_inputs.c:400:51: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-const-int-float-conversion] loads[chan] = nir_fmul_imm(b, tmp, 1.0 / BITFIELD64_MASK(bits)); ../src/gallium/drivers/radeonsi/si_nir_lower_vs_inputs.c:408:43: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-const-int-float-conversion] tmp = nir_fmul_imm(b, tmp, 1.0 / BITFIELD64_MASK(bits - 1)); Signed-off-by: Vignesh Raman Acked-by: Helen Koike Acked-by: David Heidelberg Acked-by: Yonggang Luo Part-of: --- src/gallium/drivers/freedreno/a3xx/fd3_emit.c | 4 ++-- .../drivers/radeonsi/si_nir_lower_vs_inputs.c | 4 ++-- src/mesa/main/get.c | 4 ++-- src/mesa/main/texparam.c | 14 +++++++------- src/nouveau/codegen/nv50_ir_peephole.cpp | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_emit.c b/src/gallium/drivers/freedreno/a3xx/fd3_emit.c index 32a2d6a69b0..0375c22d586 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_emit.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_emit.c @@ -728,8 +728,8 @@ fd3_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring, OUT_PKT0(ring, REG_A3XX_RB_Z_CLAMP_MIN, 2); if (depth == 32) { - OUT_RING(ring, (uint32_t)(zmin * 0xffffffff)); - OUT_RING(ring, (uint32_t)(zmax * 0xffffffff)); + OUT_RING(ring, (uint32_t)(zmin * (float)0xffffffff)); + OUT_RING(ring, (uint32_t)(zmax * (float)0xffffffff)); } else if (depth == 16) { OUT_RING(ring, (uint32_t)(zmin * 0xffff)); OUT_RING(ring, (uint32_t)(zmax * 0xffff)); diff --git a/src/gallium/drivers/radeonsi/si_nir_lower_vs_inputs.c b/src/gallium/drivers/radeonsi/si_nir_lower_vs_inputs.c index 82bd8a007e5..723dade2002 100644 --- a/src/gallium/drivers/radeonsi/si_nir_lower_vs_inputs.c +++ b/src/gallium/drivers/radeonsi/si_nir_lower_vs_inputs.c @@ -399,7 +399,7 @@ opencoded_load_format(nir_builder *b, nir_def *rsrc, nir_def *vindex, /* 2_10_10_10 data formats */ unsigned bits = log_size == 3 ? (chan == 3 ? 2 : 10) : (8 << log_size); nir_def *tmp = nir_u2f32(b, loads[chan]); - loads[chan] = nir_fmul_imm(b, tmp, 1.0 / BITFIELD64_MASK(bits)); + loads[chan] = nir_fmul_imm(b, tmp, 1.0 / (double)BITFIELD64_MASK(bits)); } break; case AC_FETCH_FORMAT_SNORM: @@ -407,7 +407,7 @@ opencoded_load_format(nir_builder *b, nir_def *rsrc, nir_def *vindex, /* 2_10_10_10 data formats */ unsigned bits = log_size == 3 ? (chan == 3 ? 2 : 10) : (8 << log_size); nir_def *tmp = nir_i2f32(b, loads[chan]); - tmp = nir_fmul_imm(b, tmp, 1.0 / BITFIELD64_MASK(bits - 1)); + tmp = nir_fmul_imm(b, tmp, 1.0 / (double)BITFIELD64_MASK(bits - 1)); /* Clamp to [-1, 1] */ tmp = nir_fmax(b, tmp, nir_imm_float(b, -1)); loads[chan] = nir_fmin(b, tmp, nir_imm_float(b, 1)); diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 02aafff7d6f..67d9b855c0f 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -83,8 +83,8 @@ FLOAT_TO_BOOLEAN(GLfloat X) static inline GLint FLOAT_TO_FIXED(GLfloat F) { - return ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : - ((F) * 65536.0f < INT_MIN) ? INT_MIN : + return ( ((F) * 65536.0f > (float)INT32_MAX) ? INT32_MAX : + ((F) * 65536.0f < (float)INT32_MIN) ? INT32_MIN : (GLint) ((F) * 65536.0f) ); } diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 001cc185722..2a921e82e22 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -54,7 +54,7 @@ /** * Use macro to resolve undefined clamping behaviour when using lroundf */ -#define LCLAMPF(a, lmin, lmax) ((a) > (lmin) ? ( (a) >= (lmax) ? (lmax) : (lroundf(a)) ) : (lmin)) +#define LCLAMPF(a, lmin, lmax) ((a) > (float)(lmin) ? ( (a) >= (float)(lmax) ? (lmax) : (lroundf(a)) ) : (lmin)) /** * Check if a coordinate wrap mode is supported for the texture target. @@ -965,8 +965,8 @@ _mesa_texture_parameterf(struct gl_context *ctx, { GLint p[4]; p[0] = (param > 0) ? - ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) : - ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5)); + ((param > (float)INT32_MAX) ? INT32_MAX : (GLint) (param + 0.5)) : + ((param < (float)INT32_MIN) ? INT32_MIN : (GLint) (param - 0.5)); p[1] = p[2] = p[3] = 0; need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa); @@ -2607,7 +2607,7 @@ get_tex_parameteriv(struct gl_context *ctx, * it cannot be represented by the returned data type, then the * nearest value representable using that type is returned. */ - *params = LCLAMPF(obj->Sampler.Attrib.MinLod, INT_MIN, INT_MAX); + *params = LCLAMPF(obj->Sampler.Attrib.MinLod, INT32_MIN, INT32_MAX); break; case GL_TEXTURE_MAX_LOD: if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) @@ -2622,7 +2622,7 @@ get_tex_parameteriv(struct gl_context *ctx, * it cannot be represented by the returned data type, then the * nearest value representable using that type is returned. */ - *params = LCLAMPF(obj->Sampler.Attrib.MaxLod, INT_MIN, INT_MAX); + *params = LCLAMPF(obj->Sampler.Attrib.MaxLod, INT32_MIN, INT32_MAX); break; case GL_TEXTURE_BASE_LEVEL: if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) @@ -2646,7 +2646,7 @@ get_tex_parameteriv(struct gl_context *ctx, * it cannot be represented by the returned data type, then the * nearest value representable using that type is returned. */ - *params = LCLAMPF(obj->Sampler.Attrib.MaxAnisotropy, INT_MIN, INT_MAX); + *params = LCLAMPF(obj->Sampler.Attrib.MaxAnisotropy, INT32_MIN, INT32_MAX); break; case GL_GENERATE_MIPMAP_SGIS: if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) @@ -2691,7 +2691,7 @@ get_tex_parameteriv(struct gl_context *ctx, * it cannot be represented by the returned data type, then the * nearest value representable using that type is returned. */ - *params = LCLAMPF(obj->Sampler.Attrib.LodBias, INT_MIN, INT_MAX); + *params = LCLAMPF(obj->Sampler.Attrib.LodBias, INT32_MIN, INT32_MAX); break; case GL_TEXTURE_CROP_RECT_OES: if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture) diff --git a/src/nouveau/codegen/nv50_ir_peephole.cpp b/src/nouveau/codegen/nv50_ir_peephole.cpp index 5f68dd2e33a..94d8a44c006 100644 --- a/src/nouveau/codegen/nv50_ir_peephole.cpp +++ b/src/nouveau/codegen/nv50_ir_peephole.cpp @@ -1636,8 +1636,8 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s) switch(i->dType) { CASE(TYPE_U16, u16, 0, UINT16_MAX, 0, UINT16_MAX, 0, UINT16_MAX); CASE(TYPE_S16, s16, INT16_MIN, INT16_MAX, INT16_MIN, INT16_MAX, 0, INT16_MAX); - CASE(TYPE_U32, u32, 0, UINT32_MAX, 0, INT32_MAX, 0, UINT32_MAX); - CASE(TYPE_S32, s32, INT32_MIN, INT32_MAX, INT32_MIN, INT32_MAX, 0, INT32_MAX); + CASE(TYPE_U32, u32, 0, (float)UINT32_MAX, 0, INT32_MAX, 0, UINT32_MAX); + CASE(TYPE_S32, s32, (float)INT32_MIN, (float)INT32_MAX, INT32_MIN, INT32_MAX, 0, INT32_MAX); case TYPE_F32: switch (i->sType) { case TYPE_F64: