llvm / llvm/llvm-project

Microsoft builtins ignore volatile qualifier

Open
#198,312 0 comments 0 reactions 0 assignees View on GitHub
clang miscompilation
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.