|
|
|
|
|
by ncmncm
1839 days ago
|
|
Right. Volatile very rarely means what peoole using it imagine it means. It very much does not mean Do What I Mean. E.g. compilers routinely elide writes to stack variables declared volatile—or even atomic—that they "know" are not aliased. So e.g. if an interrupt routine might look at things in your stack frame, you need to use asm to force it not to fool with writes there. Volatile and atomic don't help you, there, because the stack frame is special. LTO builds can expose what had been invisible operations in other TUs (".o" files) to the optimizer. So that might demand especial care. |
|
Of course how accesses on the abstract machine maps to the actual hardware is implementation defined, although most will document to translate them to plain movs.
And implementations have bugs of course; here [1] gcc removing a volatile access to an otherwise unused volatile parameter is considered a bug, even when the parameter is actually passed via register (in this case I would say the standard is underspecified).
You are absolutely correct regarding non-volatile atomics though.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71793