Fix signed min / -1.
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Apr 2014 15:06:14 +0000 (15:06 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Apr 2014 15:06:14 +0000 (15:06 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/wide-int@209750 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/wide-int.cc

index a64ed88..a99f667 100644 (file)
@@ -1727,8 +1727,10 @@ wi::divmod_internal (HOST_WIDE_INT *quotient, unsigned int *remainder_len,
       && wi::only_sign_bit_p (dividend))
     overflow = true;
 
-  /* If overflow is set, just get out.  There will only be grief by
-     continuing.  */
+  /* Handle the overflow cases.  Viewed as unsigned value, the quotient of
+     (signed min / -1) has the same representation as the orignal dividend.
+     We have traditionally made division by zero act as division by one,
+     so there too we use the original dividend.  */
   if (overflow)
     {
       if (remainder)
@@ -1739,8 +1741,9 @@ wi::divmod_internal (HOST_WIDE_INT *quotient, unsigned int *remainder_len,
       if (oflow != 0)
        *oflow = true;
       if (quotient)
-       quotient[0] = 0;
-      return 1;
+       for (unsigned int i = 0; i < dividend_len; ++i)
+         quotient[i] = dividend_val[i];
+      return dividend_len;
     }
 
   if (oflow)