This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Miscompilation of remainder expressions


David Daney wrote:
Roberto Bagnara wrote:
Robert Dewar wrote:

Roberto Bagnara wrote:

Reading the thread "Autoconf manual's coverage of signed integer
overflow & portability" I was horrified to discover about GCC's
miscompilation of the remainder expression that causes INT_MIN % -1
to cause a SIGFPE on CPUs of the i386 family.  Are there plans to
fix this bug (which, to me, looks quite serious)?
All the best,

Roberto

P.S. I checked whether this bug affects my code and it does.
      Before yesterday I was completely unsuspecting of such
      a fundamental flaw... I wonder how many know about it.


It's truly amazing for real code to be computing remainders
in this domain ... seems a bad idea to me, since very few
people are comfortably aware of what remainder means for
such cases.


Everyone knows that dividing a number by -1 or 1 gives
a 0 remainder.  To the contrary, no one expects a%b to
raise SIFPE when b != 0.


On the contrary, since the beginning of time SIGFPE has been generated on GCC/x86/linux under these conditions. This is wildly known.


Just because you just found out about it does not mean that 'no one' expects it.

OK: so it is my fault. But even if it is so wildly known, I think the GCC documentation should still mention it, for the sake of the few morons like me that are unsuspecting.

From http://en.wikipedia.org/wiki/SIGFPE

  A common oversight is to consider division by zero the only source
  of SIGFPE conditions. On some architectures (IA-32 included), integer
  division of INT_MIN, the smallest representable negative integer value,
  by -1 triggers the signal because the quotient, a positive number,
  is not representable.

Hmmm, it says nothing about the remainder.  Can some Google guru
suggest how to prove or disprove the claim that what we are
talking about is wildly known?

--
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@cs.unipr.it


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]