On Fri, Jul 20, 2018 at 05:49:12PM +0530, Umesh Kalappa wrote:
> We are looking at the C sample i.e
>
> extern int i,j;
>
> int test()
> {
> while(1)
> { i++;
> j=20;
> }
> return 0;
> }
>
> command used :(gcc 8.1.0)
> gcc -S test.c -O2
>
> the generated asm for x86
>
> .L2:
> jmp .L2
>
> we understand that,the infinite loop is not deterministic ,compiler
> is free to treat as that as UB and do aggressive optimization ,but we
> need keep the side effects like j=20 untouched by optimization .
Don't invoke UB in your code, and you won't be surprised, it is all that
easy. After you invoke UB, anything can happen.
Jakub