Received: from eggs.gnu.org ([2001:4830:134:3::10]:35576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0vJA-00042w-0Q for qemu-devel@nongnu.org; Fri, 05 Jun 2015 13:21:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0vJ6-0001e3-OT for qemu-devel@nongnu.org; Fri, 05 Jun 2015 13:21:27 -0400 Date: Fri, 5 Jun 2015 17:21:16 +0000 From: Joseph Myers In-Reply-To: <5571C679.2010202@redhat.com> Message-ID: References: <1433367941-119488-1-git-send-email-agraf@suse.de> <5571B3BE.60003@redhat.com> <5571BA13.3040507@redhat.com> <5571BE3D.9050002@redhat.com> <5571C679.2010202@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Subject: Re: [Qemu-devel] undefined behavior of signed left shifts (was Re: [PULL 00/40] ppc patch queue 2015-06-03) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: polacek@redhat.com, Peter Maydell , gcc@gcc.gnu.org, QEMU Developers , Michael Roth , Alexander Graf , "qemu-ppc@nongnu.org" On Fri, 5 Jun 2015, Paolo Bonzini wrote: > The GCC manual says "GCC does not use the latitude given in C99 and C11 > only to treat certain aspects of signed '<<' as undefined, but this is > subject to change". It would certainly be nice if they removed the > "this is subject to change" part. The correct statement would be more complicated. That is: the value returned is as documented, without that latitude being used for *optimization*, but (a) -fsanitize=undefined (and its subcase -fsanitize=shift) intends to follow exactly what the different standards specify when giving runtime errors and (b) the cases that are undefined are thereby not considered integer constant expressions (with consequent pedwarns-if-pedantic in various cases, and corner case effects on what's a null pointer constant). (The only "subject to change" would be that if there are still missing cases from the runtime detection or the not treating as integer constant expressions, then those missing cases may be fixed. I don't think it would be a good idea to add optimizations on this basis - for example, optimizations of x * 2 based on undefined overflow should not be applied to x << 1.) -- Joseph S. Myers joseph@codesourcery.com