Skip to content

reproducable wasm32 bug #85580

Closed
Closed
@gilescope

Description

@gilescope

I'm really sorry if this isn't a compiler bug, but it smells like one. I've managed to bag it into a few lines of code. Change or reorder anything and the test will pass.

If you run cargo test this repo it will pass:

https://github.com/gilescope/wasm-repro1.git

If you add in --target=wasm32-unknown-unknown it will fail. ( You will need to cargo install wasm-bindgen-cli)
It seems to correctly figure out that the condion is false but then take the true branch of the if anyway. There's no unsafe in the code so there should be no UB....

#[wasm_bindgen_test]
#[test]
fn test() {
    let s: &[u8] = &[1];
    let masked = s[0];
    // The below cond should evaluate to false but,
    // what seems to happen is even though it evaluates to false,
    // the if takes the wrong branch!!!!
    let cond = s[0] as u32 == 0; //should evaluate to false.

    // Comment out line below to pass the test on --target=wasm32-unknown-unknown ????
    let m1 = masked << 0;

    assert_eq!(Err(()), if cond {
        Ok(3333)
    } else {
        //Should go here.
        Err(())
    });
}

Why for instance does << 0 have to be there for the bug to manifest itself? I am clueless...

This is with the latest nightly ( rustc 1.54.0-nightly (5dc8789 2021-05-21) ), but have confirmed it fails on beta too.

I would love to know what is going on - it seems very wierd behaviour.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-wasmTarget: WASM (WebAssembly), http://webassembly.org/P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions