From owner-svn-src-all@freebsd.org Fri Jan 19 23:50:29 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 DFE1DECFF64; Fri, 19 Jan 2018 23:50:29 +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 B49CA7D09B; Fri, 19 Jan 2018 23:50:29 +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 w0JNoq5S081137 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 19 Jan 2018 23:50:53 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 w0JMTNqu028743 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 19 Jan 2018 15:50:22 -0800 (PST) (envelope-from truckman@FreeBSD.org) Date: Fri, 19 Jan 2018 15:50:21 -0800 (PST) From: Don Lewis Subject: Re: svn commit: r328159 - head/sys/modules To: David Chisnall cc: cem@freebsd.org, Benjamin Kaduk , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org In-Reply-To: <244014BB-C492-48A9-9F28-0A5E713DE5EB@FreeBSD.org> Message-ID: References: <201801190434.w0J4Y6i7086677@repo.freebsd.org> <244014BB-C492-48A9-9F28-0A5E713DE5EB@FreeBSD.org> 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:50:30 -0000 On 19 Jan, David Chisnall wrote: > On 19 Jan 2018, at 05:07, Conrad Meyer wrote: >> >> The spec says the behavior is undefined; not that the compiler has to >> produce a warning or error message. The compiler *does* get to >> arbitrarily decide what it wants to do when it encounters UB. It is >> wholly free to implement this particular UB with the logical result >> and no warning/error. > > First, you are not correct that the only logical outcome of a shift of > greater than the width of a type is 0. 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. Propagating the sign when doing a right shift is the common behaviour, but I believe this is actually implemenation defined. If the machine doesn't have arithmetic shift instructions, then a logical shift which fills in zeros on the left is also conformant. See the edit to the first answer here: https://stackoverflow.com/questions/1857928/right-shifting-negative-numbers-in-c I think powerpc falls into this category.