Skip to content

WASM/WebAssembly bug when compiling with opt-level=0 #47776

New issue

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

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

Already on GitHub? # to your account

Closed
adiba opened this issue Jan 26, 2018 · 1 comment
Closed

WASM/WebAssembly bug when compiling with opt-level=0 #47776

adiba opened this issue Jan 26, 2018 · 1 comment
Labels
C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@adiba
Copy link

adiba commented Jan 26, 2018

extern {
    fn log_i32(val: i32);
}

#[no_mangle]
pub fn run() {
    let s = "Tre".as_bytes();
    let len = s.len();
    unsafe {
        log_i32(len as i32);
    }
}

This should yield 3. It however gives 0 when compiling with the following command:
rustc +nightly -C opt-level=0 --target wasm32-unknown-unknown --crate-type=cdylib src/main.rs
Any opt-level above 0 is fine though. (eg rustc +nightly -C opt-level=1 --target wasm32-unknown-unknown --crate-type=cdylib src/main.rs)

The fat pointer of s contains the correct length in memory, just the len method returns the wrong value.
I only have access to the mangled opt-level=0 WAT so I cannot investigate what WASM or LLVM-IR is doing there.

@shepmaster shepmaster added O-wasm Target: WASM (WebAssembly), http://webassembly.org/ C-bug Category: This is a bug. labels Jan 26, 2018
@alexcrichton
Copy link
Member

I'm gona close this in favor of #46367 as I believe it's the same issue as that, but thanks for the report!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

3 participants