Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apple gcc bug




Aaron Jackson wrote:
On Mar 17, 2005, at 4:55 PM, Matt Watson wrote:

Sorry for jumping to the wrong conclusion. The problem is that I am doing some numerical calculations (solving nonlinear equations with a nonlinear constraint) and the algorithm I am using sometimes wanders off into nowhere (I am still debugging things). I haven't done any c programming in quite a while, and got used to the crashing behavior when I first learned and thought that was how things operated.

Since this is undefined, I would like for the program to throw a SIGFPE,

Undefined means 'undefined'. The compiler doesn't have to catch the exception, and (from Andrew Pinski's reports) the chip *doesn't* catch the exception.


In order to do what you're requesting, the compiler would have to write pre-checking code to note that it is about to do a division by 0 and manually synthesise an exception. Personally, I'd rather my compiler *not* add an extra test-compare into every division operation I program.

It's undefined because _it should never happen_, and because their are a variety of different ways the *hardware* might choose to deal with this error. The C standard tries to only mandate particular behaviour if it is necessary for correct program execution. By definition, undefined areas are *not* necessary for correct program execution, because they will never be executed by a correct program.

If your code is allowing it to happen, add a test-compare before each division operation in your code. See which one triggers.

#define MY_INT_DIV(x,y) my_checked_int_divide ((x),(y))

int
my_checked_int_divide (x,y)
{
 if (y)
 {
  return x / y;
 }
 else
 {
  // Suitable error handling goes here
 }
}

Drop a breakpoint inside that else and you get an instant stack trace whenever you attempt to divide by zero. Once you've fixed the bug, just change the divide to:

#define MY_INT_DIV(x,y) ((x)/(y))

--
Andrew White

--------------------------------------------------------------------------
This email and any attachments are confidential. They may contain legally
privileged information or copyright material. You should not read, copy,
use or disclose them without authorisation. If you are not an intended
recipient, please contact us at once by return email and then delete both
messages. We do not accept liability in connection with computer virus,
data corruption, delay, interruption, unauthorised access or unauthorised
amendment. This notice should not be removed.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >Apple gcc bug (From: Aaron Jackson <email@hidden>)
 >Re: Apple gcc bug (From: Matt Watson <email@hidden>)
 >Re: Apple gcc bug (From: Aaron Jackson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.