BUILD: atomic: prefer __atomic_compare_exchange_n() for __ha_cas_dw()
authorWilly Tarreau <w@1wt.eu>
Thu, 28 Oct 2021 06:53:33 +0000 (08:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 Oct 2021 07:45:48 +0000 (09:45 +0200)
commit4957a32f9e739e3a291dde1b5b06216f54f27083
tree9a511b2af469093b6c9b9dfaa7b211b37baf2836
parent8aee3030f8070c60c01eb9980c182c8b34b810b1
BUILD: atomic: prefer __atomic_compare_exchange_n() for __ha_cas_dw()

__atomic_compare_exchange() is incorrectly documented in the gcc builtins
doc, it says the desired value is "type *desired" while in reality it is
"const type *desired" as expected since that value must in no way be
modified by the operation. However it seems that clang has implemented
it as documented, and reports build warnings when fed a const.

This is quite problematic because it means we have to betry the callers,
pretending we won't touch their constants but not knowing what the
compiler would do with them, and possibly hiding future bugs.

Instead of forcing a cast, let's just switch to the better
__atomic_compare_exchange_n() that takes a value instead of a pointer.
At least with this one there is no doubt about how the input will be
used.

It was verified that the output object code is the same both in clang
and gcc with this change.
include/haproxy/atomic.h