From owner-svn-src-all@freebsd.org Fri Jan 19 17:37:24 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 74C0FEBE52F; Fri, 19 Jan 2018 17:37:24 +0000 (UTC) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 577256B3E0; Fri, 19 Jan 2018 17:37:23 +0000 (UTC) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (localhost [127.0.0.1]) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3) with ESMTP id w0JHbMiG073098; Fri, 19 Jan 2018 09:37:22 -0800 (PST) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: (from freebsd@localhost) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3/Submit) id w0JHbM90073097; Fri, 19 Jan 2018 09:37:22 -0800 (PST) (envelope-from freebsd) From: "Rodney W. Grimes" Message-Id: <201801191737.w0JHbM90073097@pdx.rh.CN85.dnsmgr.net> Subject: Re: svn commit: r328159 - head/sys/modules In-Reply-To: To: cem@freebsd.org Date: Fri, 19 Jan 2018 09:37:22 -0800 (PST) CC: David Chisnall , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Reply-To: rgrimes@freebsd.org X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII 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 17:37:24 -0000 [ Charset UTF-8 unsupported, converting... ] > On Fri, Jan 19, 2018 at 6:56 AM, David Chisnall 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