# stage2: improve semantics of atomic operations · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/5b1c0d922c1061706ae1673333fcfb1d8fdd4602)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 5b1c0d922c1061706ae1673333fcfb1d8fdd4602

Requested commit: 5b1c0d922c1061706ae1673333fcfb1d8fdd4602

Commit: 5b1c0d922c1061706ae1673333fcfb1d8fdd4602

Tree: 4df989a3854adeaad833ad1c9970c972a77918b4

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: improve semantics of atomic operations

ZIR instructions updated: atomic_load, atomic_rmw, atomic_store, cmpxchg
These no longer construct a pointer type as the result location. This
solves a TODO that was preventing the pointer from possibly being
volatile, as well as properly handling allowzero and addrspace.
It also allows the pointer to be over-aligned, which may be needed
depending on the target. As a consequence, the element type needs to be
communicated in the ZIR. This is done by strategically making one of the
operands be ResultLoc.ty instead of ResultLoc.coerced_ty if possible, or
otherwise explicitly adding elem_type into the ZIR encoding, such as in
the case of atomic_load.

The pointer type of atomic operations is now checked in Sema by coercing
it to an expected pointer type, that maybe over-aligned according to
target requirements.

Together with the previous commit, Zig now has smaller alignment for
large integers, depending on the target, and yet still has type safety
for atomic operations that specially require higher alignment.

```

## Parents

- [259f784241fb44e0a1b570daaf31ba2b9f164106](https://git.cafe/gitcafe/zig/commit/259f784241fb44e0a1b570daaf31ba2b9f164106?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/5b1c0d922c1061706ae1673333fcfb1d8fdd4602?format=markdown)
