Skip to content

nouveau: fix warnings about implicit-const-int-float-conversion

clang warns about converting INT32_MAX/UINT32_MAX to a float.

The CASE macro takes the following arguments and chooses which set to use depending on the first type argument: #define CASE(type, dst, fmin, fmax, imin, imax, umin, umax)

Only for type TYPE_F32 and TYPE_F64 will fmin/fmax be used. There is no reason to pass INT/UINT values for the other types. Dropping those fixes the clang warnings like these:

warning: implicit conversion from 'unsigned int' to 'float' changes value from 4294967295 to 4294967296 [-Wimplicit-const-int-float-conversion]
      CASE(TYPE_U32, u32, 0, UINT32_MAX, 0, INT32_MAX, 0, UINT32_MAX);
      ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdint.h:129:23: note: expanded from macro 'UINT32_MAX'
# define UINT32_MAX             (4294967295U)
                                 ^~~~~~~~~~~
../src/nouveau/codegen/nv50_ir_peephole.cpp:1611:68: note: expanded from macro 'CASE'
                                    CLAMP(imm0.reg.data.f64, fmin, fmax) : \
                                                                   ^~~~
../src/util/u_math.h:635:59: note: expanded from macro 'CLAMP'
#define CLAMP( X, MIN, MAX )  ( (X)>(MIN) ? ((X)>(MAX) ? (MAX) : (X)) : (MIN) )
Edited by David Heidelberg

Merge request reports