Question about GCC 5.2.0 and expression reordering

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

 



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)
2 - Is there a flag to g++ to disable this optimization only? I don’t see one that
is directly related to this kind of thing.

The generated assembly looks like the following:

   346d:	89 c7				mov    %eax,%edi
   346f:	88 84 24 a2 00 00 00 	mov    %al,0xa2(%rsp)
   3476:	83 f7 01             		xor    $0x1,%edi			// set (or clear) low bit
   3479:	83 7c 24 20 16       		cmpl   $0x16,0x20(%rsp)	// check for == URI
   347e:	75 09                		jne    3489 <_run+0x2b89>	// jump != URI
   3480:	40 84 ff             		test   %dil,%dil				// check testbit result
   3483:	0f 85 77 17 00 00    	jne    4c00 <_run+0x4300>	// jump based on testbit result

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