Skip to content

Use signext and zeroext argument attributes. #88

Closed
@sunfishcode

Description

@sunfishcode

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 {
[...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions