This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] TRACING: Fix a copmile warning
- From: Steven Rostedt <rostedt at goodmis dot org>
- To: Arnaud Lacombe <lacombar at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org, stufever at gmail dot com, linux-kernel at vger dot kernel dot org, Wang Shaoyan <wangshaoyan dot pt at taobao dot com>, Frederic Weisbecker <fweisbec at gmail dot com>, Ingo Molnar <mingo at redhat dot com>
- Date: Mon, 25 Jul 2011 20:08:54 -0400
- Subject: Re: [PATCH] TRACING: Fix a copmile warning
- References: <1310982010-13849-1-git-send-email-wangshaoyan.pt@taobao.com> <1311618747.3526.32.camel@gandalf.stny.rr.com> <CACqU3MVJ9Oj4pXH9O_2jnqDVBqKA+AgoWHwP-n2HGD4LU0pMHQ@mail.gmail.com> <1311625197.3526.35.camel@gandalf.stny.rr.com> <CACqU3MUKU_0FbOQT+TKLnnaoFVS_QOgzzx-tvunQy94v-eykTw@mail.gmail.com> <CACqU3MXO_oR+8Ac2Z7wSji0sUeu-2FwskmxZxtY9NV+XpJXuwA@mail.gmail.com> <CACqU3MW2bXNQeTDqy2NcUBzzeZ7CLNGtb3et=UHq4DRxhsFEDQ@mail.gmail.com>
On Mon, 2011-07-25 at 19:58 -0400, Arnaud Lacombe wrote:
> Hi,
> > [...]
> > In which case the warning is fully valid. I'm not sure what's the C
> > standard guarantee in term of conditional test order.
> I'd assume that the following apply:
>
> 6.5 Expressions
>
> 3 The grouping of operators and operands is indicated by the
> syntax.72) Except as specified
> later (for the function-call (), &&, ||, ?:, and comma operators),
> the order of evaluation
> of subexpressions and the order in which side effects take place are
> both unspecified.
>
>
> in which case gcc is free to do whatever it wants :(
No it does not! Read what you wrote: "Except as specified later (for the
function-call(), &&, ||, ?:...)"
&& and || must be short cuts. That is, it must evaluate the earlier
statements before the later, and exit when it can. We use that all over
the kernel (and in all C code):
if (ptr && ptr->field)
If it were to switch that to:
if (ptr->field && ptr)
we would have segfaults everywhere.
This looks like a serious gcc bug.
-- Steve