Re: Miscompilation of remainder expressions

2007-01-19 Thread Richard Guenther
On 1/19/07, Joe Buck [EMAIL PROTECTED] wrote: On Thu, Jan 18, 2007 at 05:36:23PM -0500, Robert Dewar wrote: Morten Welinder wrote: For sure a/b is undefined In C, it is. In assembler it is perfectly well defined, i.e., it traps. But how is the trap handler supposed to know the source of

Re: Miscompilation of remainder expressions

2007-01-18 Thread Andrew Haley
Ian Lance Taylor writes: Robert Dewar [EMAIL PROTECTED] writes: Ian Lance Taylor wrote: We do want to generate a trap for x / 0, of course. Really? Is this really defined to generate a trap in C? I would be surprised if so ... As far as I know, but I think it would

Re: Miscompilation of remainder expressions

2007-01-18 Thread Gabriel Dos Reis
On Thu, 18 Jan 2007, Andrew Haley wrote: | Robert Dewar writes: | Joe Buck wrote: | | (off topic!) | |On Wed, Jan 17, 2007 at 06:40:21PM -0500, Robert Dewar wrote: |H .. I wish some of the more important bugs in gcc received |the attention that this very unimportant issue

Re: Miscompilation of remainder expressions

2007-01-18 Thread Robert Dewar
Andrew Haley wrote: Mm, but although the problem being dicussed here is trivial, some of the proposed solutions aren't. As the saying goes, the cure is worse than the disease. Indeed! Well whenever you have umpteen people all trying to solve a simple problem, things always get out of hand,

Re: Miscompilation of remainder expressions

2007-01-18 Thread Robert Dewar
Gabriel Dos Reis wrote: I would say that is a bit extreme. I don't think we're going to implement any of the solutions without giving people options to disable the correct instruction generation when they don't care about it. I would hesitate a bit about options in this general class of

Re: Miscompilation of remainder expressions

2007-01-18 Thread Morten Welinder
For sure a/b is undefined In C, it is. In assembler it is perfectly well defined, i.e., it traps. But how is the trap handler supposed to know the source of a given instruction? M.

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Paubert
On Wed, Jan 17, 2007 at 12:43:40AM +0100, Vincent Lefevre wrote: On 2007-01-16 21:27:42 +, Andrew Haley wrote: Ian Lance Taylor writes: I suspect that the best fix, in the sense of generating the best code, would be to do this at the tree level. That will give loop and VRP

Re: Miscompilation of remainder expressions

2007-01-17 Thread Andrew Haley
Ian Lance Taylor writes: Gabriel Dos Reis [EMAIL PROTECTED] writes: Ian, do you believe something along the line of # I mean, could not we generate the following for %: # # rem a b := #if abs(b) == 1 # return 0 #return

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
On Wed, 17 Jan 2007, Andrew Haley wrote: | Ian Lance Taylor writes: | Gabriel Dos Reis [EMAIL PROTECTED] writes: | |Ian, do you believe something along the line of | | # I mean, could not we generate the following for %: | # | # rem a b := | #if abs(b) ==

Re: Miscompilation of remainder expressions

2007-01-17 Thread David Daney
Andrew Haley wrote: Ian Lance Taylor writes: Gabriel Dos Reis [EMAIL PROTECTED] writes: Ian, do you believe something along the line of # I mean, could not we generate the following for %: # # rem a b := #if abs(b) == 1 # return 0 #

Re: Miscompilation of remainder expressions

2007-01-17 Thread Andrew Haley
Gabriel Dos Reis writes: On Wed, 17 Jan 2007, Andrew Haley wrote: | | From a performance/convenience angle, the best place to handle this is | either libc or the kernel. Hmm, that is predicated on assumptions not convenient to users on targets that are not glibc-based or

Re: Miscompilation of remainder expressions

2007-01-17 Thread Andrew Haley
David Daney writes: That only works if the operation causes a trap. Which it does in almost all cases. Let PPC do something different, if that's what really PPC needs. Andrew.

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
On Wed, 17 Jan 2007, Andrew Haley wrote: | Gabriel Dos Reis writes: | On Wed, 17 Jan 2007, Andrew Haley wrote: | | | | | From a performance/convenience angle, the best place to handle this is | | either libc or the kernel. | | Hmm, that is predicated on assumptions not convenient to

Re: Miscompilation of remainder expressions

2007-01-17 Thread Andrew Haley
Gabriel Dos Reis writes: On Wed, 17 Jan 2007, Andrew Haley wrote: | Gabriel Dos Reis writes: | On Wed, 17 Jan 2007, Andrew Haley wrote: | | | | | From a performance/convenience angle, the best place to handle this is | | either libc or the kernel. | | Hmm, that

Re: Miscompilation of remainder expressions

2007-01-17 Thread Michael Veksler
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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
On Wed, 17 Jan 2007, Andrew Haley wrote: [...] | | To a man with a hammer, all things look like a nail. It's very | | tempting for us in gcc-land always to fix things in gcc, not because | | it's technically the right place but because it's what we control | | ourselves. | | well,

Re: Miscompilation of remainder expressions

2007-01-17 Thread Andrew Haley
Gabriel Dos Reis writes: On Wed, 17 Jan 2007, Andrew Haley wrote: [...] | | To a man with a hammer, all things look like a nail. It's very | | tempting for us in gcc-land always to fix things in gcc, not because | | it's technically the right place but because it's what we

Re: Miscompilation of remainder expressions

2007-01-17 Thread Joe Buck
On Wed, Jan 17, 2007 at 05:48:34PM +, 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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Joe Buck
On Wed, Jan 17, 2007 at 06:03:08PM +, Andrew Haley wrote: Gabriel Dos Reis writes: On Wed, 17 Jan 2007, Andrew Haley wrote: | | From a performance/convenience angle, the best place to handle this is | either libc or the kernel. Hmm, that is predicated on assumptions not

RE: Miscompilation of remainder expressions

2007-01-17 Thread Dave Korn
On 17 January 2007 19:09, Joe Buck wrote: On Wed, Jan 17, 2007 at 05:48:34PM +, 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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Joe Buck
On Wed, Jan 17, 2007 at 07:03:43PM +, Andrew Haley wrote: It's an engineering problem. We have a widget that does the wrong thing*. We have several ways to make it do the right thing, only one of which has no adverse impact on the existing users of the widget. * (in some people's

Re: Miscompilation of remainder expressions

2007-01-17 Thread Ian Lance Taylor
Joe Buck [EMAIL PROTECTED] writes: On Wed, Jan 17, 2007 at 05:48:34PM +, 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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
On Wed, 17 Jan 2007, Andrew Haley wrote: | Gabriel Dos Reis writes: | On Wed, 17 Jan 2007, Andrew Haley wrote: | | [...] | | | | To a man with a hammer, all things look like a nail. It's very | | | tempting for us in gcc-land always to fix things in gcc, not because | | |

Re: Miscompilation of remainder expressions

2007-01-17 Thread Michael Veksler
Ian Lance Taylor wrote: Joe Buck [EMAIL PROTECTED] 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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Paubert
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 +, 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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Michael Veksler
Dave Korn wrote: On 17 January 2007 19:09, Joe Buck wrote: 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

Re: Miscompilation of remainder expressions

2007-01-17 Thread Andrew Haley
Gabriel Dos Reis writes: On Wed, 17 Jan 2007, Andrew Haley wrote: | Gabriel Dos Reis writes: | On Wed, 17 Jan 2007, Andrew Haley wrote: | | [...] | | | | To a man with a hammer, all things look like a nail. It's very | | | tempting for us in gcc-land always to

Re: Miscompilation of remainder expressions

2007-01-17 Thread Joe Buck
On Wed, Jan 17, 2007 at 07:42:38PM +, Andrew Haley wrote: Gabriel Dos Reis writes: You believe there is one solution, except that it does not work for the supported target. Sorry, I don't understand what you mean by that. I suspect that he meant to write one supported target; it

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
On Wed, 17 Jan 2007, Joe Buck wrote: | On Wed, Jan 17, 2007 at 07:42:38PM +, Andrew Haley wrote: | Gabriel Dos Reis writes: |You believe there is one solution, except that it does not work for |the supported target. | | Sorry, I don't understand what you mean by that. | | I suspect

Re: Miscompilation of remainder expressions

2007-01-17 Thread Robert Dewar
H .. I wish some of the more important bugs in gcc received the attention that this very unimportant issue is receiving :-) I guess the difference is that lots of people can understand this issue. Reminds me of the hullabaloo over the Pentium division problem. The fact of the matter was

Re: Miscompilation of remainder expressions

2007-01-17 Thread Robert Dewar
Joe Buck wrote: If GCC winds up having to fix the bug in the compiler itself for PPC, then everyone could have the option of using a kernel fix or a compiler fix. But how are you going to do the kernel fix? What if the user did an integer divide and not a modulo? I suppose you could just say

Re: Miscompilation of remainder expressions

2007-01-17 Thread Robert Dewar
Ian Lance Taylor wrote: We do want to generate a trap for x / 0, of course. Really? Is this really defined to generate a trap in C? I would be surprised if so ...

Re: Miscompilation of remainder expressions

2007-01-17 Thread Ian Lance Taylor
Robert Dewar [EMAIL PROTECTED] writes: Ian Lance Taylor wrote: We do want to generate a trap for x / 0, of course. Really? Is this really defined to generate a trap in C? I would be surprised if so ... As far as I know, but I think it would be a surprising change for x / 0 to silently

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
Ian Lance Taylor [EMAIL PROTECTED] writes: | Robert Dewar [EMAIL PROTECTED] writes: | | Ian Lance Taylor wrote: | | We do want to generate a trap for x / 0, of course. | | Really? Is this really defined to generate a trap in C? | I would be surprised if so ... | | As far as I know, but

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Paubert
On Wed, Jan 17, 2007 at 04:15:08PM -0800, Ian Lance Taylor wrote: Robert Dewar [EMAIL PROTECTED] writes: Ian Lance Taylor wrote: We do want to generate a trap for x / 0, of course. Really? Is this really defined to generate a trap in C? I would be surprised if so ... As far as

Re: Miscompilation of remainder expressions

2007-01-17 Thread David Daney
Ian Lance Taylor wrote: Robert Dewar [EMAIL PROTECTED] writes: Ian Lance Taylor wrote: We do want to generate a trap for x / 0, of course. Really? Is this really defined to generate a trap in C? I would be surprised if so ... As far as I know, but I think it would be a surprising

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
Gabriel Paubert [EMAIL PROTECTED] writes: | On Wed, Jan 17, 2007 at 04:15:08PM -0800, Ian Lance Taylor wrote: | Robert Dewar [EMAIL PROTECTED] writes: | | Ian Lance Taylor wrote: | |We do want to generate a trap for x / 0, of course. | | Really? Is this really defined to generate

Re: Miscompilation of remainder expressions

2007-01-17 Thread Joe Buck
On Wed, Jan 17, 2007 at 06:40:21PM -0500, Robert Dewar wrote: H .. I wish some of the more important bugs in gcc received the attention that this very unimportant issue is receiving :-) I guess the difference is that lots of people can understand this issue. Yes, this phenomenon has

Re: Miscompilation of remainder expressions

2007-01-17 Thread Mike Stump
On Jan 17, 2007, at 4:44 PM, Gabriel Dos Reis wrote: C++ forces compilers to reveal their semantics for built-in types through numeric_limits. Every time you change the behaviour, you also implicilty break an ABI. No, the ABI does not document that the answer never changes between

Re: Miscompilation of remainder expressions

2007-01-17 Thread Gabriel Dos Reis
On Wed, 17 Jan 2007, Mike Stump wrote: | On Jan 17, 2007, at 4:44 PM, Gabriel Dos Reis wrote: | C++ forces compilers to reveal their semantics for built-in types | through numeric_limits. Every time you change the behaviour, | you also implicilty break an ABI. | | No, the ABI does not

Re: Miscompilation of remainder expressions

2007-01-17 Thread Mike Stump
On Jan 17, 2007, at 6:46 PM, Gabriel Dos Reis wrote: (1) the ABI I was talking about is that of libstdc++ (2) numeric_limits cannot change from translation unit to translation unit, within the same program otherwise you break the ODR. I guess we all agree on that. Doh! Did I

Re: Miscompilation of remainder expressions

2007-01-17 Thread Robert Dewar
Joe Buck wrote: (off topic!) On Wed, Jan 17, 2007 at 06:40:21PM -0500, Robert Dewar wrote: H .. I wish some of the more important bugs in gcc received the attention that this very unimportant issue is receiving :-) I guess the difference is that lots of people can understand this issue.

Re: Miscompilation of remainder expressions

2007-01-16 Thread Michael Veksler
Gabriel Paubert wrote: On Mon, Jan 15, 2007 at 10:34:23PM +0200, Michael Veksler wrote: Once the kernel sees the FP trap (whatever its i368 name is), it decodes the machine code and finds: idivl (%ecx). As far as I remember, this will put the result in two registers one for div_res and one

Re: Miscompilation of remainder expressions

2007-01-16 Thread Paolo Bonzini
Compared to the slow idivl, abs could be negligible, right. However, abs does introduce new data dependence which might add a noticeable cost. Is there an abs instruction in the i386 instruction set? No, the closest thing (input in eax, output in edx) is cltq addl %edx, %eax xorl %eax,

Re: Miscompilation of remainder expressions

2007-01-16 Thread Lucas (a.k.a T-Bird or bsdfan3)
Paolo Bonzini wrote: Compared to the slow idivl, abs could be negligible, right. However, abs does introduce new data dependence which might add a noticeable cost. Is there an abs instruction in the i386 instruction set? No, the closest thing (input in eax, output in edx) is cltq

Re: Miscompilation of remainder expressions

2007-01-16 Thread Paolo Bonzini
cltq addl %edx, %eax xorl %eax, %edx But the register allocations constraints are pretty heavy considering that idivl already puts strain on the RA. Paolo, what does the cltq instruction do? I cannot find it in my x86 reference manuals... Uhm, I meant cltd and it is the same as cdq in the

Re: Miscompilation of remainder expressions

2007-01-16 Thread Andrew Haley
Michael Veksler writes: 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Andrew Haley [EMAIL PROTECTED] writes: | Michael Veksler writes: | 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Andrew Haley
Gabriel Dos Reis writes: Andrew Haley [EMAIL PROTECTED] writes: | Michael Veksler writes: | 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Andrew Haley [EMAIL PROTECTED] writes: | Gabriel Dos Reis writes: | Andrew Haley [EMAIL PROTECTED] writes: | | | Michael Veksler writes: | | Roberto Bagnara wrote: | | | |Reading the thread Autoconf manual's coverage of signed integer | |overflow portability I was

Re: Miscompilation of remainder expressions

2007-01-16 Thread Roberto Bagnara
Andrew Haley wrote: Roberto Bagnara writes: 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.

Re: Miscompilation of remainder expressions

2007-01-16 Thread Andrew Haley
Roberto Bagnara writes: Andrew Haley wrote: Roberto Bagnara writes: 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Duncan Sands
On Tuesday 16 January 2007 16:50, Andrew Haley wrote: Roberto Bagnara writes: Andrew Haley wrote: Roberto Bagnara writes: Reading the thread Autoconf manual's coverage of signed integer overflow portability I was horrified to discover about GCC's miscompilation of

Re: Miscompilation of remainder expressions

2007-01-16 Thread Roberto Bagnara
Andrew Haley wrote: Roberto Bagnara writes: Andrew Haley wrote: Roberto Bagnara writes: 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Andrew Haley
Roberto Bagnara writes: Andrew Haley wrote: If the quotient a/b is *not* representable, is the behaviour of % well-defined or not? It doesn't say. To the point that, when a/b is not representable, raising SIGFPE for a%b is standard conformant behavior? Note however that I am

Re: Miscompilation of remainder expressions

2007-01-16 Thread Manuel López-Ibáñez
On 16/01/07, Duncan Sands [EMAIL PROTECTED] wrote: On Tuesday 16 January 2007 16:50, Andrew Haley wrote: Roberto Bagnara writes: Andrew Haley wrote: Roberto Bagnara writes: Reading the thread Autoconf manual's coverage of signed integer overflow portability I was

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
It's interesting that the same issue arose with GNAT, but we had no option to ignore the special case, since one of the official Ada validation test programs tested this case, and indeed as you see below there is a special test: function q (a, b : integer) return integer is begin return a

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread David Daney
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Roberto Bagnara wrote: Andrew Haley wrote: Roberto Bagnara writes: 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Roberto Bagnara wrote: To the point that, when a/b is not representable, raising SIGFPE for a%b is standard conformant behavior? possibly so .. Note however that I am not saying that the standard is not defective. Who knows how to write and submit C/C++ standard defect reports? Let us do

Re: Miscompilation of remainder expressions

2007-01-16 Thread Joe Buck
On Tue, Jan 16, 2007 at 08:22:10AM -0600, Gabriel Dos Reis wrote: I mean, could not we generate the following for %: rem a b := if abs(b) == 1 return 0 return machine-instruction a b On x86 processors that have conditional moves, why not do the equivalent of

Re: Miscompilation of remainder expressions

2007-01-16 Thread Roberto Bagnara
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Andrew Haley [EMAIL PROTECTED] writes: | Roberto Bagnara writes: | Andrew Haley wrote: |Roberto Bagnara writes: | | Reading the thread Autoconf manual's coverage of signed integer | overflow portability I was horrified to discover about GCC's | miscompilation of the

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Duncan Sands [EMAIL PROTECTED] writes: [...] | Ada semantics require INT_MIN rem -1 to be zero. I cannot see any other value as a result. -- Gaby

Re: Miscompilation of remainder expressions

2007-01-16 Thread David Daney
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Roberto Bagnara
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Gabriel Paubert wrote: \ No, because the instruction has actually two result values: - the remainder, which you could safely set to zero (not 1!) - the quotient, which is affected by the overflow and there may be compiler and languages that rely on the exception being generated. But the

RE: Miscompilation of remainder expressions

2007-01-16 Thread Dave Korn
On 16 January 2007 18:23, Robert Dewar wrote: Gabriel Paubert wrote: \ No, because the instruction has actually two result values: - the remainder, which you could safely set to zero (not 1!) - the quotient, which is affected by the overflow and there may be compiler and languages

Re: Miscompilation of remainder expressions

2007-01-16 Thread Roberto Bagnara
Robert Dewar wrote: Roberto Bagnara wrote: Andrew Haley wrote: Roberto Bagnara writes: 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Dave Korn wrote: On 16 January 2007 18:23, Robert Dewar wrote: Gabriel Paubert wrote: \ No, because the instruction has actually two result values: - the remainder, which you could safely set to zero (not 1!) - the quotient, which is affected by the overflow and there may be compiler and

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Roberto Bagnara wrote: I am sorry if I brought you to think that I am asking something for me. There is no longer a problem for me personally: I will simply stop using % in my projects (which, by the way are in C++) and will use custom functions instead. I have almost finished an Autoconf

RE: Miscompilation of remainder expressions

2007-01-16 Thread Dave Korn
On 16 January 2007 18:42, Robert Dewar wrote: Dave Korn wrote: On 16 January 2007 18:23, Robert Dewar wrote: Gabriel Paubert wrote: \ No, because the instruction has actually two result values: - the remainder, which you could safely set to zero (not 1!) - the quotient, which is

Re: Miscompilation of remainder expressions

2007-01-16 Thread Joe Buck
On Tue, Jan 16, 2007 at 12:05:12PM -0600, Gabriel Dos Reis wrote: By definition, the absolute value of a % b is always less than the absolute value of b. Consequently, a % b is always defined. Nitpick: for nonzero b.

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
On Tue, 16 Jan 2007, Joe Buck wrote: | On Tue, Jan 16, 2007 at 12:05:12PM -0600, Gabriel Dos Reis wrote: | By definition, the absolute value of a % b is always less than the | absolute value of b. Consequently, a % b is always defined. | | Nitpick: for nonzero b. yes, I assumed that -- since

Re: Miscompilation of remainder expressions

2007-01-16 Thread Roberto Bagnara
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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Roberto Bagnara wrote: You are right: I am not familiar with DO-178B certification. Fair enough, but it means you should never use avionics code as an example in such discussions. No life has ever been lost due to a software bug in the realm of commercial aviation, and that was not achieved

Re: Miscompilation of remainder expressions

2007-01-16 Thread David Daney
Roberto Bagnara wrote: 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? The point really is not how widely/wildly known the issue is. Really the thing we consider on gcc@ is: What is

Re: Miscompilation of remainder expressions

2007-01-16 Thread Joe Buck
On Tue, Jan 16, 2007 at 11:05:20AM -0800, David Daney wrote: Roberto Bagnara wrote: 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? The point really is not how widely/wildly known

Re: Miscompilation of remainder expressions

2007-01-16 Thread Robert Dewar
Andrew Haley wrote: Roberto Bagnara writes: Robert Dewar wrote: Yes, it's a bug, is it a serious bug, no? Will real software be affected? no. Indeed I find any program that actually does this remainder operation in practice to be highly suspect. But I am not wrong if I say

Re: Miscompilation of remainder expressions

2007-01-16 Thread Vincent Lefevre
On 2007-01-16 12:31:00 -0500, 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread David Daney
Vincent Lefevre wrote: On 2007-01-16 12:31:00 -0500, 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

Re: Miscompilation of remainder expressions

2007-01-16 Thread Ian Lance Taylor
Joe Buck [EMAIL PROTECTED] writes: I suggest that those who think this is a severe problem are the ones who are highly motivated to work on a solution. An efficient solution could be tricky: you don't want to disrupt pipelines, or interfere with optimizations that rely on recognizing that

Re: Miscompilation of remainder expressions

2007-01-16 Thread Andrew Haley
Ian Lance Taylor writes: Joe Buck [EMAIL PROTECTED] writes: I suggest that those who think this is a severe problem are the ones who are highly motivated to work on a solution. An efficient solution could be tricky: you don't want to disrupt pipelines, or interfere with

Re: Miscompilation of remainder expressions

2007-01-16 Thread Vincent Lefevre
On 2007-01-16 15:50:09 +, Andrew Haley wrote: This is a disgreement about interpretation of the langauge in the standard, which is: The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both

Re: Miscompilation of remainder expressions

2007-01-16 Thread David Daney
Andrew Haley wrote: Ian Lance Taylor writes: Joe Buck [EMAIL PROTECTED] writes: I suggest that those who think this is a severe problem are the ones who are highly motivated to work on a solution. An efficient solution could be tricky: you don't want to disrupt pipelines, or

Re: Miscompilation of remainder expressions

2007-01-16 Thread Ian Lance Taylor
David Daney [EMAIL PROTECTED] writes: Andrew Haley wrote: Ian Lance Taylor writes: Joe Buck [EMAIL PROTECTED] writes: I suggest that those who think this is a severe problem are the ones who are highly motivated to work on a solution. An efficient solution could be

Re: Miscompilation of remainder expressions

2007-01-16 Thread Joe Buck
On Tue, Jan 16, 2007 at 01:31:06PM -0800, David Daney wrote: Andrew Haley wrote: Ian Lance Taylor writes: I suspect that the best fix, in the sense of generating the best code, would be to do this at the tree level. That will give loop and VRP optimizations the best chance to eliminate

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Joe Buck [EMAIL PROTECTED] writes: | On Tue, Jan 16, 2007 at 11:05:20AM -0800, David Daney wrote: | Roberto Bagnara wrote: | | 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? |

Re: Miscompilation of remainder expressions

2007-01-16 Thread Ian Lance Taylor
Gabriel Dos Reis [EMAIL PROTECTED] writes: Ian, do you believe something along the line of # I mean, could not we generate the following for %: # # rem a b := #if abs(b) == 1 # return 0 #return machine-instruction a b # # On x86 processors

Re: Miscompilation of remainder expressions

2007-01-16 Thread Vincent Lefevre
On 2007-01-16 13:08:18 -0800, David Daney wrote: The difference is that your program didn't get killed by SIGFPE, it just gave incorrect results. An incorrect result is worse, but being killed by SIGFPE is still very bad. But I was mainly answering the claim hard to believe this case appears

Re: Miscompilation of remainder expressions

2007-01-16 Thread Vincent Lefevre
On 2007-01-16 21:27:42 +, Andrew Haley wrote: Ian Lance Taylor writes: I suspect that the best fix, in the sense of generating the best code, would be to do this at the tree level. That will give loop and VRP optimizations the best chance to eliminate the test for -1. Doing it

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Vincent Lefevre [EMAIL PROTECTED] writes: | On 2007-01-16 13:41:16 -0800, Ian Lance Taylor wrote: | To be clear, in my opinion, this should always be selected by an | option, it should never be default behaviour for any target. | | I disagree. One should get correct results by default. Once

Re: Miscompilation of remainder expressions

2007-01-16 Thread Andrew Pinski
Vincent Lefevre [EMAIL PROTECTED] writes: | On 2007-01-16 13:41:16 -0800, Ian Lance Taylor wrote: | To be clear, in my opinion, this should always be selected by an | option, it should never be default behaviour for any target. | | I disagree. One should get correct results by

Re: Miscompilation of remainder expressions

2007-01-16 Thread Gabriel Dos Reis
Andrew Pinski [EMAIL PROTECTED] writes: | | Vincent Lefevre [EMAIL PROTECTED] writes: | | | On 2007-01-16 13:41:16 -0800, Ian Lance Taylor wrote: | | To be clear, in my opinion, this should always be selected by an | | option, it should never be default behaviour for any target. | | |

Re: Miscompilation of remainder expressions

2007-01-16 Thread Joe Buck
On Tue, Jan 16, 2007 at 06:55:45PM -0500, Andrew Pinski wrote: Vincent Lefevre [EMAIL PROTECTED] writes: | On 2007-01-16 13:41:16 -0800, Ian Lance Taylor wrote: | To be clear, in my opinion, this should always be selected by an | option, it should never be default behaviour for any

Re: Miscompilation of remainder expressions

2007-01-15 Thread Paolo Carlini
Hi Roberto, 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

Re: Miscompilation of remainder expressions

2007-01-15 Thread Andrew Haley
Roberto Bagnara writes: 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

Re: Miscompilation of remainder expressions

2007-01-15 Thread Andrew Haley
Paolo Carlini writes: I would like to understand the issue better, however... What more is there to understand? It's an integer overflow. The processor generates a trap on integer overflows during division operations. Andrew.

  1   2   >