This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: undefined behavior of signed left shifts (was Re: [PULL 00/40] ppc patch queue 2015-06-03)
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Paolo Bonzini <pbonzini at redhat dot com>
- Cc: Peter Maydell <peter dot maydell at linaro dot org>, Alexander Graf <agraf at suse dot de>, "qemu-ppc at nongnu dot org" <qemu-ppc at nongnu dot org>, QEMU Developers <qemu-devel at nongnu dot org>, Michael Roth <mdroth at linux dot vnet dot ibm dot com>, <gcc at gcc dot gnu dot org>, <polacek at redhat dot com>
- Date: Fri, 5 Jun 2015 17:21:16 +0000
- Subject: Re: undefined behavior of signed left shifts (was Re: [PULL 00/40] ppc patch queue 2015-06-03)
- Authentication-results: sourceware.org; auth=none
- References: <1433367941-119488-1-git-send-email-agraf at suse dot de> <CAFEAcA_qVShs0+FwRGVXE=u5g1Bx9Z6knoG71rnE9mcKSEwyEg at mail dot gmail dot com> <5571B3BE dot 60003 at redhat dot com> <CAFEAcA9ZrQPf1phr5ffuzXMcVGFuGDQWqK=YmGzY2faC36p49A at mail dot gmail dot com> <5571BA13 dot 3040507 at redhat dot com> <CAFEAcA-BLmhegzqVHUH88PfHxAnBq8QYBW8UNUp858+08Db9zA at mail dot gmail dot com> <5571BE3D dot 9050002 at redhat dot com> <CAFEAcA9wASC_-dtbup=jX36NPqVw50GrhP8R-asApnFFSv5jgw at mail dot gmail dot com> <5571C679 dot 2010202 at redhat dot com>
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