Optimization level causes undesired code output

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Optimization level causes undesired code output

835 Views
manasvb
Contributor III

Am using lpc55s69.

For debug config, optimization level is None, while for release it is -Os(size optimization).

Because of this I get different code behaviour in debug and release. For release mode, I tried all the optimization levels, but I get same output, only when I disable the optimization I get correct output.

 

I dont want to disable optimization in Release and also want correct behaviour, how do I achieve this.

Labels (1)
0 Kudos
Reply
1 Reply

825 Views
ErichStyger
Specialist I

I'm afraid that you have to debug your 'wrong' code why it is failing. My experience these days is that if the output is wrong in higher optimization levels, it is likely a programming error (race condition, dangling pointers, wrong usage of memory, buffer overflow, ...).

What I recommend is that you carefully check compiler warnings, and that you increase the warning level to a 'pedantic' one. This should give you some hints.

The other approach is that you start reducing your application, to get a 'minimal failing example', to isolate the issue.

Last but not least, have a read at https://www.whyprogramsfail.com/

Good luck!

Erich

0 Kudos
Reply