Closed
Description
I tried this code:
#[repr(u8)]
pub enum DirectEnum {
A(u32),
B(u32),
}
#[repr(u8)]
pub enum IndirectEnum {
A(Value),
B(Value),
}
#[repr(C)]
pub struct Value {
val: u32,
}
#[no_mangle]
pub extern "C" fn test_direct() {
unsafe { call_with_direct(DirectEnum::B(0xFFF)) }
}
#[no_mangle]
pub extern "C" fn test_indirect() {
unsafe { call_with_indirect(IndirectEnum::B(Value { val: 0xFFF })) }
}
#[link(wasm_import_module = "something")]
extern "C" {
fn call_with_direct(a: DirectEnum);
fn call_with_indirect(a: IndirectEnum);
}
and compiled it with -C opt-level=3 --target wasm32-unknown-unknown
https://godbolt.org/z/cTqbMq
I expected to see this happen: The code should be the same for test_direct
and test_indirect
. It should push two i32 values: 1 and 4096.
Instead, this happened: test_indirect
pushes 8 values instead of two: 1, 0, 0, 0, 255, 15, 0 and 0. The numbers pushed seem to depend on the bitsize of the repr meaning only 4 values get pushed for repr(u16)