public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/30484]  New: Miscompilation of remainder expressions on CPUs of the i386 family
@ 2007-01-16 15:19 bagnara at cs dot unipr dot it
  2007-01-16 22:04 ` [Bug target/30484] " vincent at vinc17 dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: bagnara at cs dot unipr dot it @ 2007-01-16 15:19 UTC (permalink / raw)
  To: gcc-bugs

The program below shows (at all the optimization levels) a miscompilation of
the remainder expression that causes INT_MIN % -1 to cause a SIGFPE on CPUs of
the i386 family.

#include <limits.h>
#include <stdio.h>

int minus_one(int n) {
  return (n+1)*(n-1)-n*n;
}

void p(int x, int y) {
  int z = x % y;
  printf("%d %% %d -> %d\n", x, y, z);
}

int main(int argc, char** argv) {
  p(INT_MIN, minus_one(argc));
}

For simpler programs, the behavior depends on the ability of the optimizer to
realize that the divisor is -1, in which case the compiler evaluates the
remainder expression (to 0, at compile-time) and no signal is raised.

Since the remainder is always defined, this violates the C standard.

By the way, the Ariane 5 Flight 501 crash was caused by an unexpected exception
(http://en.wikipedia.org/wiki/Ariane_5_Flight_501).


-- 
           Summary: Miscompilation of remainder expressions on CPUs of the
                    i386 family
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bagnara at cs dot unipr dot it


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30484


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-02-19 13:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-16 15:19 [Bug target/30484] New: Miscompilation of remainder expressions on CPUs of the i386 family bagnara at cs dot unipr dot it
2007-01-16 22:04 ` [Bug target/30484] " vincent at vinc17 dot org
2007-01-16 22:10 ` vincent at vinc17 dot org
2007-01-16 22:11 ` pinskia at gcc dot gnu dot org
2007-01-16 22:15 ` pinskia at gcc dot gnu dot org
2007-01-17  7:14 ` jv244 at cam dot ac dot uk
2007-01-17  8:49 ` veksler at il dot ibm dot com
2008-09-12 20:34 ` nightstrike at gmail dot com
2008-09-12 20:40 ` jsm28 at gcc dot gnu dot org
2008-09-12 20:43 ` jsm28 at gcc dot gnu dot org
2009-02-21 18:45 ` jsm28 at gcc dot gnu dot org
2010-02-19 13:08 ` vincent at vinc17 dot org

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).