Your examples are not expected to work unless you specifically ask the compiler for it.
If you use the volatile key word, then you are guaranteed that all reads and stores will actually happen and not be optimized out. But volatile still allows non-atomicity and reordering so you probably want something which prohibits that too.
You mean volatile memory?
In those cases some compiler override could provide the solution, while still allowing the compiler to flag all the other cases as errors.