Skip to content

ABI adjustment code for wasm doesn't handle 128bit ints and floats #135532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bjorn3 opened this issue Jan 15, 2025 · 3 comments · Fixed by #135534
Closed

ABI adjustment code for wasm doesn't handle 128bit ints and floats #135532

bjorn3 opened this issue Jan 15, 2025 · 3 comments · Fixed by #135534
Labels
A-ABI Area: Concerning the application binary interface (ABI) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jan 15, 2025

According to https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md __int128 and long long double have to be returned indirectly. In

fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout,
{
ret.extend_integer_width_to(32);
if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) {
ret.make_indirect();
}
}
however we are not doing .make_indirect() for i128 and f128. It currently works by accident as LLVM implicitly introduces a return area pointer when returning i128 and f128, but other backends and other code that needs to know the ABI may not be able to handle this.

@bjorn3 bjorn3 added C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Jan 15, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 15, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-ABI Area: Concerning the application binary interface (ABI) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 15, 2025
@tgross35
Copy link
Contributor

long long double

Assuming this is a typo in the spec? I don't know if this is valid. Unless they really want binary256...

@bjorn3
Copy link
Member Author

bjorn3 commented Jan 15, 2025

I got confirmation on the tool-conventions PR that introduced this that it was indeed likely a mistake to write long long double instead of long double.

@tgross35
Copy link
Contributor

(for my reference WebAssembly/tool-conventions#161 (comment))

jhpratt added a commit to jhpratt/rust that referenced this issue Jan 16, 2025
…gross35

use indirect return for `i128` and `f128` on wasm32

fixes rust-lang#135532

Based on https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md we now use an indirect return for  `i128`, `u128` and `f128`. That is what LLVM ended up doing anyway.

r? `@bjorn3`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 16, 2025
…gross35

use indirect return for `i128` and `f128` on wasm32

fixes rust-lang#135532

Based on https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md we now use an indirect return for  `i128`, `u128` and `f128`. That is what LLVM ended up doing anyway.

r? ``@bjorn3``
@bors bors closed this as completed in bcd0683 Jan 17, 2025
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) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants