This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about GCC 5.2.0 and expression reordering


On 14/06/17 16:58, David Barto wrote:
> I have the following code. It is compiled at -O3 using g++
> with the -std=gnu++14 option.
> 
> The code in question is the following:
> 
>    if ( !testbit(rec_scan0,63) && f20type == URI ) {
> 
> Valgrind claims that the "Conditional jump or move depends on uninitialized value(s)"
> 
> Well, only if !testbit(rec_scan0,63) should we check the f20type value,
> right? Apparently GCC is reordering the expression. This makes no
> sense to me, from the old school of C coding.
> 
> My question is 2 fold:
> 1 - is this legal (and I think it is) and if so would someone point to the relevant
> part of the C++ standard. (I can’t find it)

Yes.  By the "as if" rule, as long as your program does what it's
supposed to do, GCC can do whatever it likes under the hood.  The
"don't evaluate the RHS of a && operator" rule only actually matters
if the RHS has a side effect.  Sure, reading an uninitialized value is
undefined behaviour, bur GCC knows that it will do no harm.

-- 
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]