zink: implicly casting integers to pointers, warnings on 32-bit compile
When compiling Mesa with zink enabled, at commit cd04b63c
[19/42] Compiling C object 'src/gallium/drivers/zink/3d02308@@zink@sta/zink_context.c.o'.
../../src/gallium/drivers/zink/zink_context.c: In function ‘zink_create_sampler_state’:
../../src/gallium/drivers/zink/zink_context.c:170:11: warning: returning ‘VkSampler’ {aka ‘long long unsigned int’} from a function with return type ‘void *’ makes pointer from integer without a cast [-Wint-conversion]
170 | return sampler;
| ^~~~~~~
../../src/gallium/drivers/zink/zink_context.c: In function ‘zink_bind_sampler_states’:
../../src/gallium/drivers/zink/zink_context.c:182:47: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
182 | ctx->samplers[shader][start_slot + i] = (VkSampler)samplers[i];
| ^
In file included from ../../src/gallium/drivers/zink/zink_batch.h:29,
from ../../src/gallium/drivers/zink/zink_context.h:28,
from ../../src/gallium/drivers/zink/zink_context.c:24:
../../src/gallium/drivers/zink/zink_context.c: In function ‘zink_delete_sampler_state’:
../../src/util/u_dynarray.h:171:59: warning: initialization of ‘VkSampler’ {aka ‘long long unsigned int’} from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
171 | #define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow_bytes((buf), 1, sizeof(type)), &__v, sizeof(type));} while(0)
| ^
../../src/gallium/drivers/zink/zink_context.c:191:4: note: in expansion of macro ‘util_dynarray_append’
191 | util_dynarray_append(&batch->zombie_samplers,
| ^~~~~~~~~~~~~~~~~~~~
VkSampler
is an opaque type, and should be simply returned by value.
For some reasons gcc doesn't detect this issue when I compile it on amd64, but it does detect it when I am cross compiling using i686-linux-gnu-gcc-9
My guess is that gcc on 64-bit doesn't complain (or complains) less because sizeof(void*) == sizeof(long long unsigned int) == sizeof(VkSampler). But on 32-bit it is not true.
Compiler: gcc 9.2.1-15 OS: Linux Debian testing amd64