Recently I happened to run into a bad code generation situation. I got a struct contains static std::atomic_ullong objects and a function performs operations on them. The code compiles and runs without any problems under debug mode. However, it gets access violation exceptions under release mode with the code optimizations applied. No such problem with either std::atomic_uint or std::atomic_ulong though. And this issue happens only with compiling against x86. After I asked on stack overflow, it seems the generated assembly code is problematic. One answer said something like this:
"EBX is used as a scratch register in the body of the function. Its value happens to be 1 by this point. So then ESP becomes 1, and then POP tries to read from that, obviously bogus, address"
My code is in the attachment file. Thanks.