Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1308889

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

From Al Viro <viro@ZenIV.linux.org.uk>
Newsgroups linux.kernel
Subject Re: [PATCH] fs: dcache: Use bool return value instead of int
Date 2016-01-14 00:00 +0100
Message-ID <qQCyu-6kn-5@gated-at.bofh.it> (permalink)
References <qPSlY-84V-13@gated-at.bofh.it> <qPTBo-vZ-25@gated-at.bofh.it> <qQePw-6Hn-5@gated-at.bofh.it> <qQfBU-7kg-21@gated-at.bofh.it> <qQCf8-6cl-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] fs: dcache: Use bool return value instead of int chengang@emindsoft.com.cn - 2016-01-11 22:40 +0100
  Re: [PATCH] fs: dcache: Use bool return value instead of int Al Viro <viro@ZenIV.linux.org.uk> - 2016-01-12 00:00 +0100
    Re: [PATCH] fs: dcache: Use bool return value instead of int David Howells <dhowells@redhat.com> - 2016-01-12 01:40 +0100
      Re: [PATCH] fs: dcache: Use bool return value instead of int Al Viro <viro@ZenIV.linux.org.uk> - 2016-01-12 02:10 +0100
    Re: [PATCH] fs: dcache: Use bool return value instead of int Chen Gang <chengang@emindsoft.com.cn> - 2016-01-12 22:40 +0100
      Re: [PATCH] fs: dcache: Use bool return value instead of int Al Viro <viro@ZenIV.linux.org.uk> - 2016-01-12 23:30 +0100
        Re: [PATCH] fs: dcache: Use bool return value instead of int Chen Gang <chengang@emindsoft.com.cn> - 2016-01-13 23:40 +0100
          Re: [PATCH] fs: dcache: Use bool return value instead of int Al Viro <viro@ZenIV.linux.org.uk> - 2016-01-14 00:00 +0100
            Re: [PATCH] fs: dcache: Use bool return value instead of int Chen Gang <chengang@emindsoft.com.cn> - 2016-01-14 16:40 +0100

csiph-web