[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1311638934.3526.43.camel@gandalf.stny.rr.com>
Date: Mon, 25 Jul 2011 20:08:54 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Arnaud Lacombe <lacombar@...il.com>
Cc: 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
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
--
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