Unexpected -Wvolatile-register-var warnings when using volatile qualifier for memory‑mapped registers
0 reputation · 03 Feb 2021, 04:16 UTC
When developing Embedded C code, engineers enable diagnostics such as -Wall -Wextra -Wvolatile-register-var to catch problematic register accesses while using #pragma GCC diagnostic push/pop or #pragma diag_suppress to silence the warning in specific blocks. The goal is to retain useful alerts for genuine issues without exposing notification noise from known‑safe volatile register operations.
However, the C standard leaves the atomicity guarantee of the volatile qualifier implementation‑defined, which creates uncertainty about whether suppressing -Wvolatile-register-var via pragmas might hide non‑atomic accesses that could be reordered or split by the optimizer at different optimization levels.
- Does the volatile qualifier guarantee atomic access to memory‑mapped registers at -O0, -O2, and -O3 when using GCC or IAR?
- If the guarantee is not provided, does suppressing -Wvolatile-register-var with diagnostic pragmas risk hiding actual non‑atomic code generation?
- Are there portable, standards‑based methods to assert atomic register access without relying solely on the volatile qualifier?