Skip to content
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

Use signext and zeroext argument attributes. #88

Closed
sunfishcode opened this issue Mar 12, 2018 · 2 comments
Closed

Use signext and zeroext argument attributes. #88

sunfishcode opened this issue Mar 12, 2018 · 2 comments

Comments

@sunfishcode
Copy link

Rust should use LLVM's signext and zeroext argument attributes for bool/i8/i16/u8/u16 types when targetting WebAssembly, for consistency with LLVM IR generated by clang, and to allow these values to be automatically interpreted by JS.

For example, on this Rust code:

#[no_mangle]
pub extern fn narrow(x: i32) -> i8 {
  x as i8
}
#[no_mangle]
pub extern fn widen(x: i8) -> i32 {
  x as i32
}

Running rustc test.rs --emit llvm-ir --crate-type=cdylib --target=wasm32-unknown-unknown produces:

[...]
define i8 @narrow(i32 %x) unnamed_addr #0 {
[...]
define i32 @widen(i8 %x) unnamed_addr #0 {
[...]

It should have attributes like this:

[...]
define signext i8 @foo(i32 %x) unnamed_addr #0 {
[...]
define i32 @bar(i8 signext %x) unnamed_addr #0 {
[...]
alexcrichton referenced this issue in alexcrichton/rust Mar 12, 2018
It actually was already using the `cabi_asmjs` module but that was by accident,
so route the new `wasm32-unknown-unknown` target to a new `cabi_wasm32` module.
The first entries in this module are to use `signext` and `zeroext` for types
that are under 32 bytes in size

Closes rust-lang-nursery/rust-wasm#88
@alexcrichton
Copy link
Contributor

Oh nice catch! I've submitted rust-lang/rust#48959 to cover this

kennytm referenced this issue in kennytm/rust Mar 15, 2018
rustc: Start a custom cabi module for wasm32

It actually was already using the `cabi_asmjs` module but that was by accident,
so route the new `wasm32-unknown-unknown` target to a new `cabi_wasm32` module.
The first entries in this module are to use `signext` and `zeroext` for types
that are under 32 bytes in size

Closes rust-lang-nursery/rust-wasm#88
@alexcrichton
Copy link
Contributor

Fixed in rust-lang/rust#48959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants