At 11:02 PM 8/26/2003, Chris Tutty wrote:
Hi,

I'm sure I've run into this before, but can't remember what the
problem was.  The symptom is that the optimiser is removing
code I consider valid, leaving certain logic non-functional.

Essentially I have a function that tests a variety of conditions,
setting a flag to false if any condition fails.  The function then
ends with the following lines:

 if (TestsOK)
 {
  return errNone;

 } else
 {
  return gInfo.ErrorCode;
 }

My problem is that with dead code elimination on, the test is
ignored and errNone is returned regardless of the state of the
TestsOK variable (which *is* false when this function exits).

Leaving aside any style issues for the moment :-), can anyone
suggest why this is happening?  The code to set the flag to true
and false in different places seems to be compiling in (although
I haven't checked the assembler yet) the compiler simply seems
to consider the if statement to be dead code.

Check the assembly. Without the whole code, I can't check to see if you've hit an IR optimizer problem. You can't trust the debugger to show you TestsOK at the end of the code, since the compiler optimized out the test, which means this variable isn't live at the end of your function and probably is sharing a register with some other variable.


You can try marking TestsOK as volatile and see how that affects code generation as well.

--
Ben Combee <[EMAIL PROTECTED]>
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com



-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to