public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: Geert Bosch <bosch@gnat.com>
Cc: <gcc@gcc.gnu.org>
Subject: Re: [PATCH] Document arithmetic overflow semantics
Date: Fri, 14 Feb 2003 18:59:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.33.0302141840230.7738-100000@kern.srcf.societies.cam.ac.uk> (raw)
In-Reply-To: <6A585B60-4020-11D7-8BD9-00039344BF4A@gnat.com>

On Fri, 14 Feb 2003, Geert Bosch wrote:

> This is indeed the reason that Ada 95 introduced bounded errors,
> where the language allows the implementation to pick any value
> in the base range of the type or raise an exception.

But in the A * 2 / 2 case, if there is overflow then the "value" selected 
for A * 2 is *not* a value of the signed type of A, and A * 2 / 2 gets a 
value that cannot be the value of dividing a signed integer by 2.  (Note 
that this optimization is a case that could actually be useful in the 
presence of macros.)  It would be reasonable enough to take code

int A, B;
/* ... */
B = A * 2 / 2;
if (B > 2000000000) { /* ... */ }
/* subsequent code using B */

and reason that B, the result of dividing an int by 2, cannot be > 
2000000000, so remove the if, but for the subsequent code compute B using 
the folding of A * 2 / 2, having a value > 2000000000.  Both optimizations 
are individually reasonable in the presence of macros or generated code, 
and the combined effect is that no single value is assumed for the result 
of the undefined code.

For the specific cases where we can *prove* that particular code, if
executed, must be undefined (use of a variable that cannot have been
initialized, shift by constant greater that width of type, A * 1000000 *
1000000, ...), the best option may be to generate a trap (as already done
for some such cases), and a mandatory warning if we can't also prove that
the code in question isn't executed (it may well be contained inside an if
(0)).

-- 
Joseph S. Myers
jsm28@cam.ac.uk

  reply	other threads:[~2003-02-14 18:51 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-13 13:24 Richard Kenner
2003-02-13 14:44 ` Roger Sayle
2003-02-13 18:39   ` Fergus Henderson
2003-02-13 19:05     ` Joe Buck
2003-02-14 13:52       ` Richard Earnshaw
2003-02-13 22:37     ` Richard Henderson
2003-02-13 22:54       ` Roger Sayle
2003-02-13 22:56       ` David Carlton
2003-02-14  0:11     ` Nathan Sidwell
2003-02-14  7:20       ` Fergus Henderson
2003-02-14 13:58         ` Geert Bosch
2003-02-14 18:59           ` Joseph S. Myers [this message]
2003-02-14 19:37         ` Joseph S. Myers
2003-02-13 16:04 ` Joe Buck
2003-02-13 16:22   ` Richard Earnshaw
2003-02-13 21:47 ` Florian Weimer
2003-02-13 14:57 Richard Kenner
2003-02-13 14:58 ` Gabriel Dos Reis
2003-02-13 15:26 ` Roger Sayle
2003-02-13 16:42   ` Joseph S. Myers
2003-02-13 17:58   ` Richard Henderson
2003-02-13 18:16     ` Roger Sayle
2003-02-13 19:46   ` Erik Trulsson
2003-02-13 15:23 Richard Kenner
2003-02-13 15:33 Richard Kenner
2003-02-13 15:36 ` Gabriel Dos Reis
2003-02-13 15:45 ` Roger Sayle
2003-02-13 15:35 Richard Kenner
2003-02-13 15:57 ` Roger Sayle
2003-02-13 15:45 Richard Kenner
2003-02-13 15:52 Richard Kenner
2003-02-13 16:03 ` Roger Sayle
2003-02-13 15:58 Richard Kenner
2003-02-13 16:10 ` Roger Sayle
2003-02-13 17:05   ` Joseph S. Myers
2003-02-13 18:05   ` Richard Henderson
2003-02-13 18:15     ` Richard Earnshaw
2003-02-13 19:03       ` Richard Henderson
2003-02-13 18:25     ` Roger Sayle
2003-02-13 18:44       ` Andrew Haley
2003-02-13 19:06       ` Richard Henderson
2003-02-13 16:09 Richard Kenner
2003-02-13 16:09 Richard Kenner
2003-02-13 17:49 ` Joe Buck
2003-02-13 16:21 Richard Kenner
2003-02-13 17:59 ` Roger Sayle
2003-02-13 17:54 Richard Kenner
2003-02-13 18:21 Robert Dewar
2003-02-13 22:04 ` Florian Weimer
2003-02-13 23:03   ` Joseph S. Myers
2003-02-15 20:52     ` Mark Hahn
2003-02-15 21:15       ` Neil Booth
2003-02-13 18:29 Richard Kenner
2003-02-13 18:56 ` Roger Sayle
2003-02-13 19:07   ` Joe Buck
2003-02-13 18:29 Richard Kenner
2003-02-13 18:33 Richard Kenner
2003-02-13 18:50 Robert Dewar
2003-02-13 18:53 Robert Dewar
2003-02-13 18:54 Robert Dewar
2003-02-13 18:58 Robert Dewar
2003-02-13 19:04 ` Andrew Haley
2003-02-13 20:55 ` Neil Booth
2003-02-13 21:10   ` Gabriel Dos Reis
2003-02-14  4:45     ` Phil Edwards
2003-02-14  8:46     ` Diego Novillo
2003-02-13 19:03 Richard Kenner
2003-02-13 19:08 Robert Dewar
2003-02-13 19:23 ` Fergus Henderson
2003-02-13 19:32 ` Andrew Haley
2003-02-13 19:10 Robert Dewar
2003-02-14  8:00 ` Fergus Henderson
2003-02-14  8:44   ` Fergus Henderson
2003-02-14 17:29     ` Michael S. Zick
2003-02-13 19:19 Robert Dewar
2003-02-13 19:56 ` Fergus Henderson
2003-02-13 19:22 Robert Dewar
2003-02-13 19:47 ` Joe Buck
2003-02-13 19:31 Robert Dewar
2003-02-13 19:42 Robert Dewar
2003-02-13 19:59 Robert Dewar
2003-02-13 20:14 Robert Dewar
2003-02-13 20:35 Robert Dewar
2003-02-13 20:41 Robert Dewar
2003-02-13 21:01 Chris Lattner
2003-02-14  8:17 ` Marcel Cox
2003-02-14 18:23   ` Joe Buck
2003-02-14 18:51     ` Nathan Sidwell
2003-02-13 21:14 Robert Dewar
2003-02-14  4:48 Robert Dewar
2003-02-14  5:57 Robert Dewar
2003-02-14  6:43 ` Chris Lattner
2003-02-14 18:14 ` Joe Buck
2003-02-14 14:14 Richard Kenner
2003-02-14 14:24 Robert Dewar
2003-02-16  5:52 ` Segher Boessenkool
2003-02-14 14:58 Richard Kenner
2003-02-14 15:26 Robert Dewar
2003-02-16 16:17 Robert Dewar
2003-02-18  6:41 ` Segher Boessenkool
2003-02-18  6:49   ` Fergus Henderson
2003-02-18 18:13   ` Joe Buck

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=Pine.LNX.4.33.0302141840230.7738-100000@kern.srcf.societies.cam.ac.uk \
    --to=jsm28@cam.ac.uk \
    --cc=bosch@gnat.com \
    --cc=gcc@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).