[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <mcrfwltoov5.fsf@coign.corp.google.com>
Date: Mon, 25 Jul 2011 17:41:02 -0700
From: Ian Lance Taylor <iant@...gle.com>
To: Arnaud Lacombe <lacombar@...il.com>
Cc: Steven Rostedt <rostedt@...dmis.org>, gcc-help@....gnu.org,
stufever@...il.com, linux-kernel@...r.kernel.org,
Wang Shaoyan <wangshaoyan.pt@...bao.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Ingo Molnar <mingo@...hat.com>
Subject: Re: [PATCH] TRACING: Fix a copmile warning
Arnaud Lacombe <lacombar@...il.com> writes:
> gcc will only emits the warning at -Os. It seems to me that the
> resulting code clearly ends-up testing an uninitialized value, ie.
> assuming the following test-case:
>
> extern void *e(void);
> extern void *f(void);
> extern void g(void);
>
> void fn(void)
> {
> void *b, *a;
>
> a = e();
> if (a != 0)
> b = f();
> if (a != 0 && b != 0)
> g();
> }
>
> ...
>
> It seems gcc transforms the conditional from:
>
> if (a != NULL && b != NULL) ...
>
> to
>
> if (b != NULL && a != NULL) ...
>
> In which case the warning is fully valid. I'm not sure what's the C
> standard guarantee in term of conditional test order. gcc 4.7.0 has
> the same behavior.
Not quite. C guarantees that && is executed in order. In this case gcc
is generating
a = e();
if (a != NULL)
b = f();
if (a != NULL & b != NULL)
g();
Note the change from && to & in the last conditional. This
transformation is safe, in that it does not change the meaning of the
program. However, it does cause a read of an uninitialized memory
location, and this is causing a later gcc pass to generate a false
positive warning.
Please consider filing a bug report about this false positive. Thanks.
Ian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists