This is the mail archive of the gcc-bugs@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]

Re: Illegal optimization in presence of setjmp


> Dear gcc-bugs,
> 
> In the small program below, the result obtained with no optimization
> and with -O2 are different. Yet, no warning is issued whatsoever.
> 
> The test has been run on gcc 2.95.2, Solaris 5.6/7, i386 and sparc
> architectures.
> 
>     
>     ravel% gcc -Wall bug.c -o bug
>     ravel% ./bug
>     Test 1: i=0
>     Test 2: i=1
>     Test 3: i=1
>     ravel% gcc -Wall -O2 bug.c -o bug
>     ravel% ./bug
>     Test 1: i=0
>     Test 2: i=1
>     Test 3: i=0

You need to declare 'i' volatile, otherwise it will be held in a register 
that is restored by the longjump.

R.



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