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