Re: [PATCH] fs: dcache: Use bool return value instead of int

From: Al Viro
Date: Wed Jan 13 2016 - 17:55:00 EST


On Thu, Jan 14, 2016 at 06:39:53AM +0800, Chen Gang wrote:

> > As for the inlines... frankly, if gcc generates a different code from having
> > replaced int with bool in those, it's time to do something very nasty to
> > gcc developers.
> >
>
> Could you provide the related proof?

static inline _Bool f(.....)
{
return <int expression>;
}

...
if (f(.....))

should generate the code identical to
if ((_Bool)<int expression>)
which, in turn, should generate the code identical to
if (<int expression> != 0)
and
if (<int expression>)

Neither explicit nor implicit conversion to _Bool (the former by the explicit
cast, the latter - by declaring f() to return _Bool) matters at all when the
damn thing is inlined in a condition context. Conversion to _Bool is
equivalent to comparison with 0, and so is the use in condition of if() and
friends.

For something not inlined you might get different code generated due to a
difference in calling sequences of _Bool(...) and int(...); for inlined
case having one of those variants produce a better code means that compiler
has managed to miss some trivial optimization in all other variants.

And I'm yet to see any proof that gcc *does* fuck up in that fashion. It
might - dumb bugs happen to everyone, but I would not assume that they'd
managed to do something that bogys without experimental evidence.