# stage2: improve \`@sizeOf\` and \`@alignOf\` integers · gitcafe/zig

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

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

Visibility: public

Requested revision: 259f784241fb44e0a1b570daaf31ba2b9f164106

Requested commit: 259f784241fb44e0a1b570daaf31ba2b9f164106

Commit: 259f784241fb44e0a1b570daaf31ba2b9f164106

Tree: ff024852310df27dfad242c12af8d8a77a290988

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: improve `@sizeOf` and `@alignOf` integers

Prior to this commit, the logic for ABI size and ABI alignment for
integers was naive and incorrect. This results in wasted hardware as
well as undefined behavior in the LLVM backend when we memset an
incorrect number of bytes to 0xaa due to disagreeing with LLVM about the
ABI size of integers.

This commit introduces a "max int align" value which is different per
Target. This value is used to derive the ABI size and alignment of all
integers.

This commit makes an interesting change from stage1, which treats
128-bit integers as 16-bytes aligned for x86_64-linux. stage1 is
incorrect. The maximum integer alignment on this system is only 8 bytes.
This change breaks the behavior test called "128-bit cmpxchg" because on
that target, 128-bit cmpxchg does require a 16-bytes aligned pointer to
a 128 bit integer. However, this alignment property does not belong on
*all* 128 bit integers - only on the pointer type in the `@cmpxchg`
builtin function prototype. The user can then use an alignment override
annotation on a 128-bit integer variable or struct field to obtain such
a pointer.

```

## Parents

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

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