# stage2 llvm: Use unpacked struct for unions and arrays · gitcafe/zig

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

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

Visibility: public

Requested revision: 2eaef84ebe968224b0cf25206abf12ea1c5e0f5a

Requested commit: 2eaef84ebe968224b0cf25206abf12ea1c5e0f5a

Commit: 2eaef84ebe968224b0cf25206abf12ea1c5e0f5a

Tree: e1fe357fb3dac1e21fd90c143d2ecc5396d3c470

Author: Cody Tapscott

Committer: Andrew Kelley

## Message

````
stage2 llvm: Use unpacked struct for unions and arrays

Our lowerings for various LLVM types assume that we can anticipate the
alignment/layout that LLVM will generate. Among other things, this
requires that we keep the alignment of our lowered LLVM types
synchronized with their expected alignment in Zig.

 - Arrays were using packed struct types, which is seems to be
   incorrect since array elements are supposed to be self-aligned.

 - Unions were using packed struct types for their payload, which causes
   layout divergence between what stage2 expects and what LLVM generates

Consider this lowered union type:
```llvm
%Value = type { <{ i64, [8 x i8] }>, i1, [7 x i8] } ; 24 bytes, align(1)
%ErrorUnion = type { %Value, i16 } ; 26 bytes, align(2)
```

Zig expects Value to be align(8) and, by extension, for ErrorUnion to be
size 32.

````

## Parents

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

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