Files
rust/tests/codegen-llvm
Jonathan Brouwer af5ab5897b Rollup merge of #162806 - folkertdev:wasm-union-abi, r=alexcrichton
wasm: correctly implement `union` trivial aggregates

A union with two scalar fields, even if they overlap exactly, is not a trivial aggregate, based on the implementation in `clang`:

e78970f80f/clang/lib/CodeGen/ABIInfoImpl.cpp (L338-L402)

It never explicitly considers unions, but essentially views them as records. The `clang` implementation is a plausible interpretation of the specification (though I'd like it to be a bit clearer):

83e5d715d0/BasicCABI.md (function-arguments-and-return-values)

> [2] Any struct or union that recursively (including through nested structs, unions, and arrays) contains just a single scalar value and is not specified to have greater than natural alignment.

We previously got this wrong. I also don't think this was really tested very well, so I added a bunch of test for various cases.

This change moves away from using the `homogeneous_aggregate` method, which is convenient because it is a bit broken and now we don't have to consider wasm when we fix that.

I've validated this against `clang` with abi-cafe.

r? alexcrichton
2026-09-15 16:46:25 +02:00
..
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

The files here use the LLVM FileCheck framework, documented at https://llvm.org/docs/CommandGuide/FileCheck.html.

One extension worth noting is the use of revisions as custom prefixes for FileCheck. If your codegen test has different behavior based on the chosen target or different compiler flags that you want to exercise, you can use a revisions annotation, like so:

// revisions: aaa bbb
// [bbb] compile-flags: --flags-for-bbb

After specifying those variations, you can write different expected, or explicitly unexpected output by using <prefix>-SAME: and <prefix>-NOT:, like so:

// CHECK: expected code
// aaa-SAME: emitted-only-for-aaa
// aaa-NOT:                        emitted-only-for-bbb
// bbb-NOT:  emitted-only-for-aaa
// bbb-SAME:                       emitted-only-for-bbb