public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeffrey A Law <law@cygnus.com>
To: kenner@vlsi1.ultra.nyu.edu (Richard Kenner)
Cc: gcc@gcc.gnu.org
Subject: Re: Pathalogical divides
Date: Sat, 23 Sep 2000 13:38:00 -0000	[thread overview]
Message-ID: <810.969669639@upchuck> (raw)
In-Reply-To: <10009211926.AA26210@vlsi1.ultra.nyu.edu>

  In message < 10009211926.AA26210@vlsi1.ultra.nyu.edu >you write:
  > Consider the following program on x86:
  > 
  > int rem (int a, int b) { return a % b; }
  > 
  > int
  > main ()
  > {
  >   printf ("%d\n", rem (0x80000000, -1));;
  > }
  > 
  > When run, rather than producing zero, as expected, it gets a SIGFPE.
  > This is because the division of the largest negative integer by negative on
  > e
  > results in an overflow.
  > 
  > So the first question is whether this is valid C behavior.
Not valid C behavior.

  > Next, compile the above with -O3 on an x86 and notice that GCC gets a
  > SIGFPE when constant-folding.
  > 
  > Finally, consider:
  > 
  > int
  > foo (int a, int b)
  > {
  >   return (a - ((a == 0x80000000 && b == -1) ? 0 : a % b)) / b;
  > }
  > 
  > This program when passed "normal" arguments does not get an overflow.
  > But GCC pulls the conditional out of the subtraction and division and
  > causes the compiler to run into the SIGFPE above.
  > 
  > I think the compiler crash needs to be fixed.  We can do it either by
  > protecting the integer part of simplify_binary_operation against SIGFPE
  > just like the FP or explicitly testing for this case just like we
  > check for divide by zero.
We need to fix the compiler crash.
jeff

  parent reply	other threads:[~2000-09-23 13:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-21 12:12 Richard Kenner
2000-09-22  1:45 ` Andreas Schwab
2000-09-23 13:38 ` Jeffrey A Law [this message]
2000-09-25  6:53   ` Alexandre Oliva
2000-09-24 22:53 ` Geoff Keating
2000-09-25  2:35 Robert Dewar
2000-09-24 23:29 ` Geoff Keating
2000-09-25  2:43 Richard Kenner
2000-09-25 14:27 ` Geoff Keating
2000-09-26  4:37   ` Jamie Lokier
2000-09-25  5:19 Robert Dewar
2000-09-25  6:57 Robert Dewar

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=810.969669639@upchuck \
    --to=law@cygnus.com \
    --cc=gcc@gcc.gnu.org \
    --cc=kenner@vlsi1.ultra.nyu.edu \
    /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).