Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar

From: Peter Zijlstra

Date: Mon Jan 12 2026 - 07:32:33 EST


On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:

> #define __READ_ONCE(x) \
> ({ \
> __unqual_scalar_typeof(x) __x = \
> (*(volatile typeof(__x) *)(&(x))); \
> mb(); \
> (typeof(x))__x; \
> })
> combined with
> typedef struct {
> uid_t val;
> } kuid_t;
>
> IOW, it complains about a cast from structure to itself, which is fair
> enough - C is pretty clear about not allowing any typecasts to or from
> non-scalar types, tautological or not.
>
> Why do we even need that cast? Seeing that generic __READ_ONCE() is
> #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
> the cast added on alpha seems to be pointless.

The problem was things like test_bit() that take a volatile argument,
doing READ_ONCE() on them would instantiate a volatile temporary and GCC
would end up generating shit code.

The __unqual_scalar_typeof() was the result of trying to remove CV
qualifiers from a type.