On 06/24/2014 03:00 AM, Peter Maydell wrote: > On 24 June 2014 10:50, Leon Alrae <leon.al...@imgtec.com> wrote: >> On 20/06/2014 21:50, Aurelien Jarno wrote: >>> I do wonder if we shouldn't use sextract32() instead of open coding that >>> now that it is available: >>> >>> offset = sextract32(ctx->opcode, 0, 19) << 3; >> >> This looks better, thanks for the suggestion (but since the offset's >> size is 18, third argument will be 18, not 19). > > This is undefined behaviour in C because of the shift into > the sign bit. Better to shift first and then signextend: > > offset = sextract32(ctx->opcode << 3, 0, 21);
Not true. Because we know from the extract that the value has 13 copies of the sign bit. Shifting by 3 isn't going to cause problems. It's shifting a *different* bit into the sign position that's (one's compliment) undefined. r~ PS: Honestly, all these compilers/sanitizers should grow a "No One's Compliment" switch to disable all the stupid stuff.