> that may appear to be an intermediate value to a C compiler, and thus escape -Wunused-variable.
It does indeed (I checked):
$ cat test.c
#include <stdint.h>
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
struct vdev;
typedef struct vdev vdev_t;
struct vdev
{
uint64_t vdev_ashift;
void *vdev_tsd;
vdev_t *vdev_top;
};
struct vdev_raidz;
typedef struct vdev_raidz vdev_raidz_t;
struct vdev_raidz
{
int vd_original_width;
int vd_physical_width;
int vd_nparity;
};
extern uint64_t vdev_raidz_get_logical_width(vdev_raidz_t *, uint64_t);
static uint64_t
vdev_raidz_asize_to_psize(vdev_t *vd, uint64_t asize, uint64_t txg)
{
vdev_raidz_t *vdrz = vd->vdev_tsd;
uint64_t psize;
uint64_t ashift = vd->vdev_top->vdev_ashift;
uint64_t cols = vdrz->vd_original_width;
uint64_t nparity = vdrz->vd_nparity;
cols = vdev_raidz_get_logical_width(vdrz, txg);
psize = (asize >> ashift);
psize -= nparity * DIV_ROUND_UP(psize, cols);
psize <<= ashift;
return (asize);
}
$ gcc-14 -Wall -Wextra -Wpedantic -Wunused -Wunused-variable -Wunused-but-set-variable -c test.c -o test.o
test.c:28:5: warning: ‘vdev_raidz_asize_to_psize’ defined but not used [-Wunused-function]
28 | vdev_raidz_asize_to_psize(vdev_t *vd, uint64_t asize, uint64_t txg)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
$ clang-19 -Weverything -c test.c -o test.o
test.c:33:31: warning: implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]
33 | uint64_t cols = vdrz->vd_original_width;
| ~~~~ ~~~~~~^~~~~~~~~~~~~~~~~
test.c:34:34: warning: implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]
34 | uint64_t nparity = vdrz->vd_nparity;
| ~~~~~~~ ~~~~~~^~~~~~~~~~
test.c:28:5: warning: unused function 'vdev_raidz_asize_to_psize' [-Wunused-function]
28 | vdev_raidz_asize_to_psize(vdev_t *vd, uint64_t asize, uint64_t txg)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
(The unused-function diagnostic is expected for this test)
I would have also expected clang to catch the double assignment to cols, to be honest.