[Bug c/27116] New: Incorrect integer division (wrong sign).
The following test demonstrates an incorrect sign in the following division : #include int main (void) { volatile long int n; n = -2; printf ("%ld\n", (-2147483647L - 1L) / (-n)); return 0; } I get a correct result with 4.0.3, and a wrong sign with snapshots 20060325 and 20060408. Also reported in debian : http://bugs.debian.org/361883 -- Summary: Incorrect integer division (wrong sign). Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: laurent at komite dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27116
[Bug c/27116] [4.2 Regression] Incorrect integer division (wrong sign).
--- Comment #2 from laurent at komite dot net 2006-04-11 15:06 --- (In reply to comment #1) > Overflow flag set problem: > > n = -2; > n.10 = n; > D.2132 = -08000 / n.10; > > -fwrapv "fixes" the problem. This is a dup of ... I'm not sure this is just an overflow problem, it might be more general. As suggested by a friend, I tried the simple example : int f (int a, int b) { return (-a) / (-b); } The assembly and `-fdump-tree-all' output show that both negations are removed, which is incorrect since the input domain is not symmetric wrt 0. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27116