http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56982

--- Comment #14 from Mikael Pettersson <mikpe at it dot uu.se> ---
(In reply to Bernd Edlinger from comment #13)
> Created attachment 30431 [details]
> another example of wrong compilation
> 
> This is another example where the optimization can
> go wrong.
> 
> The attached program produces expected results if
> compiled with -O0:
> x=0, a=1
> x=1, a=1
> a=1
> 
> But if compiled with -O3 and if the value "a" is placed
> in a register the result is like this:
> x=0, a=1
> x=1, a=0
> a=0
> 
> That is because longjmp has more semantic than just a branch:
> It branches to the setjmp, and restores all callee saved registers to
> the previos value.

Your example is invalid C.  Referring to WG14 n1494.pdf (there may be more
recent C1x documents, but it's the one I had available right now):

- you violate 7.13.1.1 which specifies where setjmp() may be called, an
assignment statement is not one of the permitted contexts

- more importantly, your auto variable a is not volatile-qualified, which means
that its value is indeterminate after the longjmp (7.13.2.1).

Please fix these issues and check again if it yields wrong results.

Reply via email to