public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Vincent Lefevre <vincent+gcc@vinc17.org>
To: gcc-help@gcc.gnu.org
Subject: Re: how to make gcc warn about arithmetic signed overflow
Date: Fri, 27 Sep 2013 09:28:00 -0000	[thread overview]
Message-ID: <20130927092841.GB10027@ypig.lip.ens-lyon.fr> (raw)
In-Reply-To: <52454087.3090208@redhat.com>

On 2013-09-27 09:23:35 +0100, Andrew Haley wrote:
> On 09/27/2013 08:57 AM, Vincent Lefevre wrote:
> > On 2013-09-26 18:30:10 +0100, Andrew Haley wrote:
> >> On 09/26/2013 06:02 PM, Vincent Lefevre wrote:
> >>> On 2013-09-26 15:49:05 +0100, Andrew Haley wrote:
> >>>> On 09/26/2013 09:29 AM, Vincent Lefevre wrote:
> >>>>> On 2013-09-25 22:29:58 -0400, James K. Lowden wrote:
> >>>>>> You mean that a naïve rendering of the source code implies an overflow
> >>>>>> where none might exist in the actual emitted object code.  And,
> >>>>>> presumably, the converse: that even if the source is written such that
> >>>>>> there logically can't be an overflow, the compiler might render object
> >>>>>> code that does.
> >>>>>
> >>>>> The converse is forbidden.
> >>>>
> >>>> You'll find it hard to justify that by any language in the standard.
> >>>
> >>> What do you mean?
> >>
> >> There is no reason why a compiler should not generate an overflow
> >> where none is written in the program, as long as it doesn't generate
> >> a different result.
> > 
> > OK, I wouldn't call that an overflow, then.
> 
> As far as the processor is concerned, what sets the overflow flag is
> an overflow.  That's the context of this discussion.

No, it isn't. If you regard the CPU overflow flag as a part of the
result, then the compiler is not allowed to generate overflows not
expressed in the source. Never. For instance, it would be really
wrong to get spurious crashes with -ftrapv just because gcc modified
the order of operations or just because the overflow flag has been
set with an unsigned operation (at the C level).

If you disregard the CPU overflow flag, then what the CPU does is
not regarded as an overflow.

Note that Dave Allured asked whether there is a way to check the
CPU overflow flag on an example where there may be an overflow
*in the source*.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

  reply	other threads:[~2013-09-27  9:28 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-21 16:45 wempwer
2013-09-21 17:24 ` Jonathan Wakely
2013-09-21 17:41   ` wempwer
2013-09-21 18:30     ` Jonathan Wakely
2013-09-21 18:50       ` wempwer
2013-09-21 19:55         ` Jędrzej Dudkiewicz
2013-09-21 20:16           ` wempwer
2013-09-21 20:52             ` Jędrzej Dudkiewicz
2013-09-21 21:07               ` wempwer
2013-09-23  4:04       ` James K. Lowden
2013-09-23  7:55         ` Jonathan Wakely
2013-09-23 15:47           ` James K. Lowden
2013-09-23 21:50             ` Jonathan Wakely
2013-09-23 22:44               ` James K. Lowden
2013-09-23 23:20                 ` Jonathan Wakely
2013-09-23 19:38         ` Dave Allured - NOAA Affiliate
2013-09-23 19:43           ` Oleg Endo
2013-09-23 20:37             ` Dave Allured - NOAA Affiliate
2013-09-23 19:48           ` Andrew Haley
2013-09-23 22:00             ` James K. Lowden
2013-09-24 17:48               ` Andrew Haley
2013-09-26  2:30                 ` James K. Lowden
2013-09-26  8:29                   ` Vincent Lefevre
2013-09-26 14:49                     ` Andrew Haley
2013-09-26 17:03                       ` Vincent Lefevre
2013-09-26 18:19                         ` Andrew Haley
2013-09-27  7:58                           ` Vincent Lefevre
2013-09-27  8:23                             ` Andrew Haley
2013-09-27  9:28                               ` Vincent Lefevre [this message]
2013-09-27  9:43                                 ` Andrew Haley
2013-09-26 17:41                   ` Andrew Haley
2013-09-24  7:42           ` Brian Drummond
2013-09-21 17:53   ` Marc Glisse
2013-09-21 18:09     ` wempwer
2013-09-21 18:27       ` Jonathan Wakely
2013-09-21 19:32         ` wempwer
2013-09-22 15:52           ` Jonathan Wakely
2013-09-23 13:04           ` David Brown
2013-09-21 17:36 ` Brian Drummond
2013-09-21 17:45   ` wempwer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130927092841.GB10027@ypig.lip.ens-lyon.fr \
    --to=vincent+gcc@vinc17.org \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).