svn commit: r328159 - head/sys/modules

Don Lewis truckman at FreeBSD.org
Fri Jan 19 23:55:39 UTC 2018


On 19 Jan, Conrad Meyer wrote:
> On Fri, Jan 19, 2018 at 9:37 AM, Rodney W. Grimes
> <freebsd at pdx.rh.cn85.dnsmgr.net> wrote:
>> 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).
> 
> This is a logical right shift by a constant larger than the width of
> the left operand.  As a result, it would a constant zero in any
> emitted machine code.  It is a bug in the C standard and a concession
> to naive, non-optimizing compilers that this is considered UB.

Generating one answer when compiler knows that everything is constant
and can figure out the "correct" value at compile time, but generating
an entirely different answer when the shift value is still constant, but
passed in as a function parameter and hides that information from the
compiler so the result is generated at runtime sounds like a good way to
introduce bugs.



More information about the svn-src-head mailing list