Re: [PATCH] bio: gcc warning fix.

From: Peter Osterlund
Date: Sat Jan 07 2006 - 07:24:05 EST


Al Viro <viro@xxxxxxxxxxxxxxxx> 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@xxxxxxxxx
http://web.telia.com/~u89404340
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/