I don't understand why plain old volatile wouldn't be enough to prevent constant propagation.
See https://www.embedded.com/combining-cs-volatile-and-const-key... for examples, https://en.cppreference.com/w/cpp/language/cv for a more formal description.