Re: 2.6.14 assorted warnings

From: Alan Cox
Date: Sun Oct 30 2005 - 16:47:09 EST


On Gwe, 2005-10-28 at 03:30 -0400, Dave Jones wrote:
> gcc is dumb, it doesn't realise that the variable will be filled by another
> function if its passed thus..
>
> unsigned long foo
> bar(&foo)
> if (foo==1)
> ...
>
> With bar() filling in content of foo.
> I believe there's at least once instance of this in gcc bugzilla.

gcc is a *LOT* smarter than you give it credit for. It will not warn for
cases where it isn't able to tell how foo is used passed with &foo. It
will warn for cases where it can

Compile the following program with and without -O2 and you'll see just
how smart gcc actually is

#include <stdio.h>

static void bar(char *x) {
*x = 1;
}

static void baz(char *x) {
printf("Wombat\n");
}

int main(int argc, char *argv[]) {
char x,y;
bar(&x);
baz(&y);

printf("%c,%c\n", x, y);
}

So I'd go look deeper for real bugs

Alan


-
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/