public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Osterlund <petero2@telia.com>
To: Al Viro <viro@ftp.linux.org.uk>
Cc: Zan Lynx <zlynx@acm.org>, Jens Axboe <axboe@suse.de>,
	Jesper Juhl <jesper.juhl@gmail.com>,
	Khushil Dep <khushil.dep@help.basilica.co.uk>,
	Luiz Fernando Capitulino <lcapitulino@mandriva.com.br>,
	akpm <akpm@osdl.org>, lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] bio: gcc warning fix.
Date: 07 Jan 2006 13:22:48 +0100	[thread overview]
Message-ID: <m3y81sw7l3.fsf@telia.com> (raw)
In-Reply-To: <20060106195631.GW27946@ftp.linux.org.uk>

Al Viro <viro@ftp.linux.org.uk> writes:

> On Fri, Jan 06, 2006 at 12:33:56PM -0700, Zan Lynx wrote:
> > On Fri, 2006-01-06 at 19:48 +0100, Jens Axboe wrote:
> > > On Fri, Jan 06 2006, Jesper Juhl wrote:
> > > > gcc is right to warn in the sense that it doesn't know if
> > > > bvec_alloc_bs() will read or write into idx when its address is passed
> > > 
> > > The function is right there, on top of bio_alloc_bioset(). It's even
> > > inlined. gcc has absolutely no reason to complain.

> And yes, if you inline it manually gcc _will_ see that everything's OK.
> Path that confuses it is
> 	default in switch -> exit from bio_alloc_bs() -> l1 -> use of idx
> and 
> 		return value will be NULL	=>	  we will go to l2
> is what it doesn't notice when it inlines itself.

With my compiler (gcc 4.0.2 from FC4), it's the "unlikely" construct
that confuses the gcc warning logic, not the inlining. I get the
warning if I compile the following code with "gcc -Wall -O2 -S
test.c":

	int f(int x)
	{
		int a;
		int b = 0;
		if (x) {
			a = 1;
			b = 1;
		}
		if (__builtin_expect(!b, 0))
			return 0;
		return a;
	}

However, removing the __builtin_expect makes the warning go away.

Interestingly, changing the source so that a is initialized to some
value will make the warning go away without changing the compiled
code. Apparently, the compiler eventually realizes that the initial
value of a is never used, but it realizes it after deciding if the
warning should be generated.

-- 
Peter Osterlund - petero2@telia.com
http://web.telia.com/~u89404340

  reply	other threads:[~2006-01-07 12:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-06 15:48 [PATCH] bio: gcc warning fix Khushil Dep
2006-01-06 18:41 ` Jesper Juhl
2006-01-06 18:48   ` Jens Axboe
2006-01-06 18:53     ` Jesper Juhl
2006-01-06 18:58     ` Luiz Fernando Capitulino
2006-01-06 19:04       ` Jens Axboe
2006-01-06 19:05       ` Jesper Juhl
2006-01-06 19:33     ` Zan Lynx
2006-01-06 19:56       ` Al Viro
2006-01-07 12:22         ` Peter Osterlund [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-01-06 15:07 Luiz Fernando Capitulino
2006-01-06 15:28 ` Jens Axboe
2006-01-06 15:39 ` Al Viro
2006-01-06 22:43   ` Daniel Barkalow
2006-01-06 22:52     ` Jesper Juhl
2006-01-06 23:13       ` Daniel Barkalow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3y81sw7l3.fsf@telia.com \
    --to=petero2@telia.com \
    --cc=akpm@osdl.org \
    --cc=axboe@suse.de \
    --cc=jesper.juhl@gmail.com \
    --cc=khushil.dep@help.basilica.co.uk \
    --cc=lcapitulino@mandriva.com.br \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ftp.linux.org.uk \
    --cc=zlynx@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox