Date: Fri, 19 Jan 2018 09:37:22 -0800 (PST) From: "Rodney W. Grimes" <freebsd@pdx.rh.CN85.dnsmgr.net> To: cem@freebsd.org Cc: David Chisnall <theraven@freebsd.org>, src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r328159 - head/sys/modules Message-ID: <201801191737.w0JHbM90073097@pdx.rh.CN85.dnsmgr.net> In-Reply-To: <CAG6CVpV6Suft3v-=08f5UH6BTH2NEJgU_4kYd-UphLZ6yoJB4Q@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[ Charset UTF-8 unsupported, converting... ] > On Fri, Jan 19, 2018 at 6:56 AM, David Chisnall <theraven@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@freebsd.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801191737.w0JHbM90073097>