This patch cleanup the sema checking around the atomic builtins. This patch does two main things:
- Diagnose when a pointer to const T is used as the first argument in at atomic builtin unless that builtin is a load operation. This is already checked for C11 atomics builtins but not for __atomic ones.
- For certain atomic builtins, if the second or third argument is a pointer, allow that argument to propagate extra cv-qualifiers on the pointee to the deduced type.
The following builtins are allowed to have a const qualified pointee type as the second argument:
- __atomic_store
- __atomic_exchange
The following builtins are allowed to have a volatile qualified pointee type as the second argument:
- __atomic_store,
- __atomic_load
- __atomic_exchange
- __atomic_compare_exchange
- __atomic_compare_exchange_n
- __c11_atomic_compare_exchange_strong.
- __c11_atomic_compare_exchange_weak.
The following builtins are allowed to have a const qualified pointee type as the third argument:
- __atomic_exchange
- __atomic_compare_exchange.
The following builtin are allowed to have a volatile qualified pointee type as the third argument:
- __atomic_compare_exchange.
I don't think the %0 here is really adding anything to the diagnostic; if anything, it seems to distract from the point by making the user wonder if there's a difference between their %1 and the expected %0.