The following C code:
unsigned int wrong(unsigned int n){
return (n%2) ? 0 : 42;
}

should return 42 when n is odd and 0 when n is even.

But ARM gcc 8.2 with -O3 produces following assembly:

tst r0, #1
moveq r0, #42
movne r0, #0
bx lr

tst r0,#1 sets Z=1 iff r0 is even, and moveq r0,#42 executes iff Z=1,
therefore
it sets r0 to 42 when r0 is even, which is wrong given the C code above (
it should return 0 ).

Reply via email to