Illegal optimization in presence of setjmp
Richard Earnshaw
rearnsha@arm.com
Mon Jan 8 05:32:00 GMT 2001
> 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.
More information about the Gcc-bugs
mailing list