[PATCH 02/10] compiler.h: add is_const() as a replacement of __is_constexpr()
David Laight
David.Laight at ACULAB.COM
Fri Dec 6 19:43:39 UTC 2024
From: Willy Tarreau
> Sent: 06 December 2024 19:39
> On Fri, Dec 06, 2024 at 11:15:20AM -0800, Linus Torvalds wrote:
> > On Fri, 6 Dec 2024 at 11:07, David Laight <David.Laight at aculab.com> wrote:
> > >
> > > I'm missing the compiler version and options to generate the error.
> >
> > Just -Wall with most recent gcc versions seems to do it. At least I
> > can repro it with gcc-14.2.1 and something silly like this:
> >
> > $ cat t.c
> > int fn(int a) { return (a<<2)?1:2; }
> > $ gcc -Wall -S t.c
> > t.c: In function 'fn':
> > t.c:1:26: warning: '<<' in boolean context, did you mean '<'?
> > [-Wint-in-bool-context]
> >
> > > Does a '+ 0' help? "(var << 2) + 0 ? 0 : 0"
> >
> > Yeah, that actually works.
> >
> > And "+0" is nice in that it should work in any context.
>
> I've already used "+0" to shut certain warnings, I don't really remember
> which one, but also remember it was OK everywhere I needed.
I've often used +0u when -Wsign-compare is enabled.
Much safer than a cast.
>
> Another trick I've been using to shut up the compiler is a cast via typeof
> and an intermediary variable:
>
> #define shut_up(expr) \
> ({ \
> typeof(expr) _expr_ = expr; \
> _expr_; \
> })
That is like OPTIMISER_HIDE_VAR() and can't be used in a 'constant integer expression'.
I suspect it also has the same nasty habit of adding an extra register move.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
More information about the dri-devel
mailing list