[clang] [z/OS][Clang] Add compare and swap builtin functions (PR #202362)

Ulrich Weigand via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 29 03:05:51 PDT 2026


uweigand wrote:

Hmm, interesting.  Not sure this difference is observable under normal circumstances, but if the z/OS builtins are guaranteed to perform the store unconditionally, I agree this should be followed.

That said, I guess it would still in principle be possible to achieve the same effect, using the old-style GCC `__sync_val_compare_and_swap` builtin:

```
unsigned int old, mem, newval;

int test_atomic() {
    unsigned int oldval = old;
    unsigned int memval = __sync_val_compare_and_swap(&mem, oldval, newval);
    old = memval;
    return memval != oldval;
}
```

However, with the current back-end it seems you'll be getting slightly less efficient assembler; this could likely be fixed in the back-end, but you'd still have to rely on optimization being enabled.

In the end, I guess having this as separate builtins is fine with me.



https://github.com/llvm/llvm-project/pull/202362


More information about the cfe-commits mailing list