"compiler optimized variable out" problems since upgrading to 2.2

Discussion in 'iPhone/iPad Programming' started by beachdog, Dec 17, 2008.

  1. macrumors member

    Joined:
    Aug 10, 2008
    #1
    Not sure if anyone else has seen this, but since a recent upgrade to 2.2 I am experiencing this weird problem in gdb when running my app in debug configuration in the simulator. As I step through code in gdb, local variables that I have declared are not showing in the variable display, and if I right mouse on them in the code window I get a message along the lines of "compiler optimized this variable out". What's worse, when I hit a line of code that tests the value of that variable, the comparison takes the incorrect path leading to various application errors. Maybe this is something I have got wrong in my code, but it's pretty basic (the piece of code where I have this problem, that is).
     
  2. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    I've seen something like this using SDK 2.1 as well, twice maybe, but never narrowed it down enough to post a sufficiently detailed bug report. Changing a variable from a float to an Int32, and moving it's declaration from block local to local to instance to global seemed to seemed to change whether I could examine the variable, which way a conditional statement branched, and whether I could even assign another global from it. Might be a compiler code generation or optimization bug.

    .
     
  3. thread starter macrumors member

    Joined:
    Aug 10, 2008
    #3
    The strange thing is that it is doing any optimization at all, as this is a debug target. Is there some setting I can use to prevent any optimization? I checked the target settings and I don't see anything specific to the optimization level. It is definitely an optimization issue of some kind, because when I step through it in the debugger it jumps past whole lines at times, so it's clearly optimized the code from how it is written.
     
  4. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #4
    Yes, I think I've seen the same thing at -O0 level as well. I had to hoist the variables up into being volatile global variables, with maybe both float and int copies, to get something to appear in the debugger.

    They were originally loop temporaries IIRC. So it might be some sort of code generation bug for register assignment of loop locals.

    .
     
  5. thread starter macrumors member

    Joined:
    Aug 10, 2008
    #5
    Hmm, you're right on. My problem also has to do with loop variables -- I tried both iterating an enumerator as well as a for loop in this specific location, and both showed the problem. I then moved by loop variables from local to instance variables of the class this instance method is in, and voila, no problem -- same experience as you.

    I'm not exactly sure whether I can create a simple reusable test case to show this, since I have lots of similar looping constructs elsewhere in my code that work properly. I can't think of anything particularly noteworthy about this code, other than it is called from an IBAction callback hooked to a button click. If I have time I will try to see if I can recreate some sort of test case I could submit to Apple. For that matter, I have not had to submit a bug report before, does anyone have the url for that?

    Of course, this is a pretty ugly workaround, but at least it gets me out of the mud for now. Many thanks!
     
  6. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    Please do! Start Here:
    http://developer.apple.com/bugreporter/

    Don't forget to read the documentation on recommended practices if you want your bug report more promptly reviewed (or even fixed!).

    .
     

Share This Page