typo in definition of atomic_exchange_explicit for Clang on Unix
Summary
stdatomic.h says:
#define atomic_exchange_explicit(obj, desired, order) \
__c11_atomic_exchange_explicit(obj, expected, order)
This only works if the second argument to that macro is the identifier 'expected'. Otherwise this (hopefully) produces a 'no such local variable' message from the compiler.
Steps to reproduce
Compile queue.c
with compiler options that trigger the faulty macro.
The original code in queue.c
is:
item = atomic_exchange(&(lh->items[idx]),
(uintptr_t)&queue->taken);
This produces the following line after preprocessing:
item = __c11_atomic_exchange_explicit(&(lh->items[idx]), expected, memory_order_seq_cst);
This line does not contain queue->taken
anymore.
What is the current bug behavior?
Compilation fails because expected
is not a defined variable.
What is the expected correct behavior?
Compilation succeeds.
Possible fixes
Write 'desired' instead of 'expected'.
Edited by Roland Illig