[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aWUM9L_4MKjlXcui@willie-the-truck>
Date: Mon, 12 Jan 2026 15:02:12 +0000
From: Will Deacon <will@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Al Viro <viro@...iv.linux.org.uk>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Eric Dumazet <edumazet@...gle.com>, oe-kbuild-all@...ts.linux.dev,
linux-kernel@...r.kernel.org, Jakub Kicinski <kuba@...nel.org>,
Maciej Żenczykowski <maze@...gle.com>,
"Paul E. McKenney" <paulmck@...nel.org>
Subject: Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
On Mon, Jan 12, 2026 at 01:37:22PM +0100, Peter Zijlstra wrote:
> On Sun, Jan 11, 2026 at 06:20:10PM +0000, Al Viro wrote:
> > On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:
> >
> > > Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...
> >
> > FWIW, there's a way to strip qualifiers from *any* non-array type.
> > Look:
> >
> > void f(void)
> > {
> > const int x;
> > x = 1; // an error
> > typeof(((typeof(x)(*)(void))0)()) y;
> > y = 2; // perfectly fine
> > }
> >
> > The way it works is that qualifiers are stripped from return type when
> > deriving a function type. That was spelled out only in C17; 6.7.6.3[5]
> > | If, in the declaration "T D1", D1 has the form
> > | D ( parameter-type-list )
> > | or
> > | D ( identifier-list[opt] )
> > | and the type specified for ident in the declaration "T D" is
> > | "derived-declarator-type-list T", then the type specified for ident
> > | is "derived-declarator-type-list function returning the unqualified version
> > | of T".
> > but that "unqualified version of..." matched the common practice in
> > earlier variants of standard; they stopped issuing TCs by that point
> > (~2014), but both clang and gcc behave that way with any variant of
> > standard.
> >
> > IOW, this
> >
> > #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> >
> > would do the right thing without that _Generic cascade and it'll work
> > just fine for e.g. kuid_t. Using it for an array would trigger an error,
> > array-returning functions being forbidden...
> >
> > Guys, do you have any problems with replacing __unqual_scalar_typeof()
> > uses with that thing?
>
> There is also __typeof_unqual__, but I do not know if that is now
> supported by all compilers, if so that is the better option. If not,
> your function return type thing is awesome.
Agreed, that's a really neat trick. I wouldn't put it past somebody to
use READ_ONCE() on an array, but the build systems should shake any of
those out pretty quickly.
Will
Powered by blists - more mailing lists