This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/30484] New: Miscompilation of remainder expressions on CPUs of the i386 family
- From: "bagnara at cs dot unipr dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jan 2007 15:19:40 -0000
- Subject: [Bug target/30484] New: Miscompilation of remainder expressions on CPUs of the i386 family
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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