Re: Question about GCC 5.2.0 and expression reordering

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Jun 14, 2017, at 9:37 AM, Andrew Haley <aph@xxxxxxxxxx> wrote:
> 
> 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

Thanks for that. Can you point to the relevant portion of the standard that
I can then quote back to my Boss who is quite concerned about this?
And if there is such a flag to disable the “Optimization” performed here
what would I enable?

David Barto
barto@xxxxxxxxxxxxxxxxxxxxxx

Sometimes, my best code does nothing. Most of the rest of it has bugs.







[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux