Skip to content

wasm: fix ABI for enums with integer layout and ZST fields - #162826

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
folkertdev:wasm-int-enum-abi
Sep 16, 2026
Merged

rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
folkertdev:wasm-int-enum-abi

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

fixes #121408
follow-up to #162806

Clang is doing something that is rather annoying for us to emulate: like with unions it looks at the structure of the type, not the representation. But in rust an enum that is represented as an integer is not considered an aggregate at all, yet may still need to be passed as one if it has any (even ZST) fields.

r? alexcrichton
cc @hanna-kruppe

@folkertdev folkertdev added O-wasm Target: WASM (WebAssembly), http://webassembly.org/ A-ABI Area: Concerning the application binary interface (ABI) labels Sep 15, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 15, 2026
@folkertdev folkertdev changed the title Wasm int enum abi wasm: fix ABI for enums with integer layout and ZST fields Sep 15, 2026
@alexcrichton

Copy link
Copy Markdown
Member

@bors r+

Thanks for this! Perhaps at some point in the future I'd love to pick your brain on the ABI going-ons here to the extent that I want to define a new ABI for wasm where that'd be a good spot to fix all quirks we know of, but that's a conversation for a later time...

@rust-bors

rust-bors Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8aff3e6 has been approved by alexcrichton

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 16, 2026
…excrichton

wasm: fix ABI for enums with integer layout and ZST fields

fixes rust-lang#121408
follow-up to rust-lang#162806

Clang is doing something that is rather annoying for us to emulate: like with unions it looks at the structure of the type, not the representation. But in rust an `enum` that is represented as an integer is not considered an `aggregate` at all, yet may still need to be passed as one if it has any (even ZST) fields.

r? alexcrichton
cc @hanna-kruppe
rust-bors Bot pushed a commit that referenced this pull request Sep 16, 2026
Rollup of 7 pull requests

Successful merges:

 - #156216 (implement const Iterator for Range)
 - #162748 (Enable LLVM Thin LTO for LoongArch64)
 - #162769 (Yeet the `DeepRegionResolver` (earlier called `OpportunisticRegionResolver`))
 - #162800 (Cleanups related to RefDecodable)
 - #162826 (wasm: fix ABI for enums with integer layout and ZST fields)
 - #159359 ([rustc_public] Enhance PassMode API)
 - #162818 (Add regression test for malformed RPITIT bound ICE with the new solver)
{
// The base case: a single scalar is a singleton scalar.
if !layout.is_aggregate() {
if !(layout.is_aggregate() || layout.peel_transparent_wrappers(cx).is_enum()) {

@bjorn3 bjorn3 Sep 16, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected enums with data to already be considered an aggregate when #[repr] other than #[repr(Rust)] is used, even if the data is a ZST.

View changes since the review

rust-bors Bot pushed a commit that referenced this pull request Sep 16, 2026
Rollup of 10 pull requests

Successful merges:

 - #156216 (implement const Iterator for Range)
 - #160697 (rustc: Tweak the effect of `--jobs` on frontend parallelism)
 - #162748 (Enable LLVM Thin LTO for LoongArch64)
 - #162769 (Yeet the `DeepRegionResolver` (earlier called `OpportunisticRegionResolver`))
 - #162794 (Simplify `ast::UseTreeKind`)
 - #162800 (Cleanups related to RefDecodable)
 - #162826 (wasm: fix ABI for enums with integer layout and ZST fields)
 - #159359 ([rustc_public] Enhance PassMode API)
 - #162196 (Offload cmake cleanups)
 - #162818 (Add regression test for malformed RPITIT bound ICE with the new solver)
@rust-bors
rust-bors Bot merged commit f6b5137 into rust-lang:main Sep 16, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 16, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 16, 2026
Rollup merge of #162826 - folkertdev:wasm-int-enum-abi, r=alexcrichton

wasm: fix ABI for enums with integer layout and ZST fields

fixes #121408
follow-up to #162806

Clang is doing something that is rather annoying for us to emulate: like with unions it looks at the structure of the type, not the representation. But in rust an `enum` that is represented as an integer is not considered an `aggregate` at all, yet may still need to be passed as one if it has any (even ZST) fields.

r? alexcrichton
cc @hanna-kruppe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ABI Area: Concerning the application binary interface (ABI) O-wasm Target: WASM (WebAssembly), http://webassembly.org/ S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clang vs wasm32-{emscripten,wasi} rustc C ABI mismatch w.r.t. "singleton" unions

4 participants