On Wed, Jan 17, 2007 at 11:17:36AM -0800, Ian Lance Taylor wrote: > Joe Buck <[EMAIL PROTECTED]> writes: > > > On Wed, Jan 17, 2007 at 05:48:34PM +0000, Andrew Haley wrote: > > > From a performance/convenience angle, the best place to handle this is > > > either libc or the kernel. Either of these can quite easily fix up > > > the operands when a trap happens, with zero performance degradation of > > > existing code. I don't think there's any need for gcc to be altered > > > to handle this. > > > > 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.) > > We do want to generate a trap for x / 0, of course. >
Then you have to fix the code generation for PPC, which never traps. All (?) 3-register arithmetic instructions have the option to set an overflow flag that you can check later. Gabriel