Dave Korn writes: > On 07 November 2006 16:33, Andrew Haley wrote: > > > Ricardo FERNANDEZ PASCUAL writes: > > > > I have done some experiments to try to understand what is happening, and > > > I am a bit confused by the bahavior of GCC. Consider the following C > > > function: > > > > > > static struct { int w; } s; > > > > > > void wait (void) { > > > int t; > > > loop: > > > t = *((volatile int *) &s.w); > > > if (t > 0) goto loop; > > > } > > > > > > > > > The code generated by "cc1 -O3" on x86 is: > > > > > > wait: > > > movl s, %eax > > > pushl %ebp > > > movl %esp, %ebp > > > testl %eax, %eax > > > jg .L6 > > > popl %ebp > > > ret > > > .L3: > > > .L6: > > > jmp .L6 > > > > > > > > > Which does not seem to respect the semantics of volatile. Is this the > > > expected behavior or is this a bug? > > > > I think it's a bug. > > > > FWIW, the folowing function: > > > which looks right. A temporary shouldn't make any difference here. > > Can I just remind everyone we had a huge long thread with this discussion > last year and it might be worth reviewing. Look for the thread titled > "volatile semantics" running from Tue 03/05/2005 09:42 to Tue 26/07/2005 > 00:09. (We should try not to repeat too much of a three-month long debate!)
Yeah it was, and there was a decision: http://gcc.gnu.org/ml/gcc/2005-07/msg00731.html So no, we don't have to revisit it. Paolo Bonzini has come up with a simple fix. Andrew.