Understanding the Impact of Optimization Flags on Security
In the bug report you linked, the developer tries to overwrite the password in memory. This changes only the memory contents and has no other side effects.
An optimizing compiler may change the code in any way it likes as long as it does not change the behavior of the program. The behavior of the program is its input and output, but not its memory contents. So if you overwrite a password in memory, the compiler is free to remove that, since removing it has no effect on the working of the program.
I think as a developer you need to accept the fact that you have no control over the memory contents, instead of fighting the compiler.