From 3a343682c01eb70d6b4a65a9efe4cbb2e46c374c Mon Sep 17 00:00:00 2001 From: rsandifo Date: Thu, 24 Apr 2014 15:06:14 +0000 Subject: [PATCH] Fix signed min / -1. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/wide-int@209750 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/wide-int.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc index a64ed88..a99f667 100644 --- a/gcc/wide-int.cc +++ b/gcc/wide-int.cc @@ -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) -- 2.7.4