I'm compiling some 'C' code. I initialize some variables, then use these initialized variables in a decision block with branches that depend on the value. Since the variables have been initialized to something, they will always take the same branch.
However these decision blocks are inside a 'while loop', and interrupts or other code can change the value, causing another branch to be taken.
My compiler seeing the unreachable branch at compile time optimizes out the code for this branch.
The normal way to fix this undesired optimization is to declare the variable 'volatile'. If that's done then the compiler will not consider the branch unreachable.
I have quite a few of these decision blocks in my code, with a large number of variables that should be declared volatile. Volatile variables cause more code to be generated, since the compiler will reload the variable each time that it's used. Since I have a limited amount of code space, I don't want to declare a lot of variables volatile.
I want to turn off compiler optimization that eliminates unreachable branches, but keeps all other optimization.
My present optimization is -Os.