svn commit: r328159 - head/sys/modules

Rodney W. Grimes freebsd at pdx.rh.CN85.dnsmgr.net
Fri Jan 19 17:37:24 UTC 2018


[ Charset UTF-8 unsupported, converting... ]
> On Fri, Jan 19, 2018 at 6:56 AM, David Chisnall <theraven at freebsd.org> wrote:
> > In C, a right-shift of a signed type propagates the sign bit.  Right shifting a negative 32-bit int by 16 and then again by 16 is not undefined behaviour (though doing the shift as a single operation is) and will give you a value of -1.
> 
> The left hand operand under discussion is unsigned.  In LLVM/assembler
> terms, this is a logical right shift, not an arithmetic right shift.
> It is by definition zero filled from the left.

If you think in assembler it is easy to understand why this is UB,
most (all) architectures Right Logic or Arithmetic Shift only accept an
operand that is a size that can hold log2(wordsize).

Do you want the compiler to emmit multiple Shift instructions for your
oversized operand?    Do you want it to emmit a loop reducing your
oversized operand by log2(wordsize) each time through the loop until
your operand is < log2(wordsize)?

Bite the bullet, this is bad code, and should be fixed, not
simply sweep under the carpet cause it fails on i386.


-- 
Rod Grimes                                                 rgrimes at freebsd.org


More information about the svn-src-head mailing list