As described in-depth in rule DCL34-C. Use volatile for data that cannot be cached, a volatile
-qualified variable "shall be evaluated strictly according to the rules of the abstract machine" [ISO/IEC 9899:2011]. In other words, the volatile
qualifier is used to instruct the compiler to not make caching optimizations about a variable.
...
The workarounds proposed by Eide and Regehr fix many of the volatile
-access bugs in the tested compilers. However, compilers are always changing, so critical sections of code should be compiled as if for deployment and the compiled object code should be inspected for the correct behavior.
Risk
...
Assessment
The volatile
qualifier should be used with caution in mission-critical situations. Always make sure code that assumes certain behavior when using the volatile
qualifier is inspected at the object code level for compiler bugs.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL17-C | medium | probable | high | P4 | L3 |
Related Guidelines
Bibliography
[Eide and Regehr] | "Volatiles Are Miscompiled, and What to Do about It" |
---|---|
[ISO/IEC 9899:2011 |
...
] | Section 6.7.3, "Type |
...
Bibliography
...
Qualifiers" |
...