Topic: Debugging optimized code (Was: Optimizing function return values)


Author: bill@amber.ssd.csd.harris.com (Bill Leonard)
Date: 1995/06/08
Raw View
In article <3q6qo1$b27@punchdown.zocalo.com>, Kalyan Kolachala <kal@chromatic.com> writes:
> With debugging on, optimizations are generally disabled.

The word "generally" is not applicable here.  It is true that *some*
compilers do not allow optimization with debugging, but many do.

> If there are no bugs in the compilers then there shouldn't
> be any difference in functionality between optimized and
> non-optimized code.

This is true only if there are also no bugs in the program.  I have
seen many cases of bugs in programs that cause different behavior with
and without optimization.  For instance, forgetting to initialize a local
variable, without optimization, may result in using a stack location with
random contents.  With optimization, it may result in using a register
with *different* random contents.

I've even seen cases where the non-optimized version showed no ill effects,
while the optimized code failed.  This was not a bug in the compiler, but a
bug in the code that only mattered when optimization was turned on.  The
usual cause of such bugs is that the program has violated an aliasing
restriction that is only taken advantage of by the optimizer.

This is one of the reasons why disabling optimization with debugging is a
poor choice for a compiler vendor to make.

--
Bill Leonard
Harris Computer Systems Corporation
2101 W. Cypress Creek Road
Fort Lauderdale, FL  33309
Bill.Leonard@mail.hcsc.com

These opinions and statements are my own and do not necessarily reflect the
opinions or positions of Harris Computer Systems Corporation.

------------------------------------------------------------------------------
More people run Windows on their home computers than on any other home
appliance.
------------------------------------------------------------------------------