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


Ian Lance Taylor wrote:
Joe Buck <Joe.Buck@synopsys.COM> writes:

How will the kernel know whether the overflow in the divide instruction
is because the user's source code has a '%' and not a '/'? We generate
the exact same instruction for i / minus_one(), after all, and in that
case the trap really should be there.

We don't need to generate a trap for INT_MIN / -1. That is undefined
signed overflow. We can legitimately set the quotient register to
INT_MIN while setting the remainder register to zero. (Hmmm, what
should we do if -ftrapv is set? Probably generate a different code
sequence in the compiler.)
Simply let the kernel/libc set the overflow flag in this case, and let the compiler
append an INTO instruction right after the idivl.
We do want to generate a trap for x / 0, of course.

Ian



--
Michael Veksler
http:///tx.technion.ac.il/~mveksler


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