From owner-svn-src-all@freebsd.org Fri Jan 19 23:55:39 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9B8EAED0379; Fri, 19 Jan 2018 23:55:39 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from mx2.catspoiler.org (mx2.catspoiler.org [IPv6:2607:f740:16::d18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "amnesiac", Issuer "amnesiac" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 770357D5C6; Fri, 19 Jan 2018 23:55:39 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org ([76.212.85.177]) by mx2.catspoiler.org (8.15.2/8.15.2) with ESMTPS id w0JNu2ss081154 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 19 Jan 2018 23:56:03 GMT (envelope-from truckman@FreeBSD.org) Received: from mousie.catspoiler.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.15.2/8.15.2) with ESMTPS id w0JMTNqx028743 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 19 Jan 2018 15:55:31 -0800 (PST) (envelope-from truckman@FreeBSD.org) Date: Fri, 19 Jan 2018 15:55:31 -0800 (PST) From: Don Lewis Subject: Re: svn commit: r328159 - head/sys/modules To: cem@freebsd.org cc: "Rodney W. Grimes" , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org In-Reply-To: Message-ID: References: <201801191737.w0JHbM90073097@pdx.rh.CN85.dnsmgr.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=us-ascii Content-Disposition: INLINE X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jan 2018 23:55:39 -0000 On 19 Jan, Conrad Meyer wrote: > On Fri, Jan 19, 2018 at 9:37 AM, Rodney W. Grimes > 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.