Re: GC, variable optimized away wrongly?
Re: GC, variable optimized away wrongly?
- Subject: Re: GC, variable optimized away wrongly?
- From: Kyle Sluder <email@hidden>
- Date: Wed, 25 Nov 2009 05:04:11 -0800
On Wed, Nov 25, 2009 at 4:50 AM, Nick Rogers <email@hidden> wrote:
> In my app running on snow leopard, in a particular situation I'm getting an undesired behavior.
> Debugging a "for loop" shows a still in scope variable being optimized away.
Barring a *serious* bug in the compiler, optimization does not
introduce such behavior. So the bug is yours, the optimization is
just interfering with your ability to fix it.
> NSTimeInterval etaDouble = interval * ((totalBlocks - blockCount) / blockCount); // * debugger doesn't list this variable, mouse shows a pop up saying "variable optimized away by compiler"
> int eta = (int)etaDouble; // value is 0 here instead of something
The compiler's data flow analysis can prove that etaDouble is only
ever used to initialize eta, so it is simply skipping emitting code
for an etaDouble variable altogether. This is not why your value is
0.
> Why the certain variables are not listed in debugger window (only in GC-only projects)?
Data flow analysis will be subject to the garbage collection rules,
just like anything else.
> Why is etaDouble is being optimized away?
Because it is unused.
> Any suggestions?
Disable optimizations on your debug builds (-O0).
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden