Microsoft builtins ignore volatile qualifier
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
All Microsoft builtins do have volatile qualifier on pointer argument, e.g:
```
def InterlockedAnd : MSLangBuiltin, MSInt8_16_32Template {
let Spellings = ["_InterlockedAnd"];
let Attributes = [NoThrow];
let Prototype = "T(T volatile*, T)";
}
```
All MS builtins are lowered by clang frontend in MakeBinaryAtomicValue, which emits non-volatile atomicrmw instruction, effectively ignoring the volatile qualifier. This results in idempotent volatile atomics being optimized out.
In contrast, clang atomics are declared as variadic functions
```
def AtomicAddFetch : AtomicBuiltin {
let Spellings = ["__atomic_add_fetch"];
let Attributes = [CustomTypeChecking];
let Prototype = "void(...)";
}
```
which allows detection if we have volatile arg or not during type checking.
Contributor guide
Assessment
This issue has not been assessed yet.