Stream: git-wasmtime

Topic: wasmtime / issue #4632 'attempt to add with overflow' ?


view this post on Zulip Wasmtime GitHub notifications bot (Aug 07 2022 at 08:41):

Zhangyx24 labeled issue #4632:

Test Case

test-wat.txt
test-rs.txt
test.rs is uploaded as test-rs.txt, test.wat is uploaded asa test-wat.txt.

Steps to Reproduce

cargo run -q --example test

Expected Results

sum_i32_host Results: 3
sum_i32_host Results: -656906904
sum_i32_host Results: 2124157492

Actual Results

Extracting export...
Calling func1...
sum_i32_host Results: 3
thread 'main' panicked at 'attempt to add with overflow', test.rs:24:17
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Versions and Environment

Wasmtime version or commit: 0.38.0

Operating system: macOS10.15 and ubuntu20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Aug 07 2022 at 08:41):

Zhangyx24 opened issue #4632:

Test Case

test-wat.txt
test-rs.txt
test.rs is uploaded as test-rs.txt, test.wat is uploaded asa test-wat.txt.

Steps to Reproduce

cargo run -q --example test

Expected Results

sum_i32_host Results: 3
sum_i32_host Results: -656906904
sum_i32_host Results: 2124157492

Actual Results

Extracting export...
Calling func1...
sum_i32_host Results: 3
thread 'main' panicked at 'attempt to add with overflow', test.rs:24:17
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Versions and Environment

Wasmtime version or commit: 0.38.0

Operating system: macOS10.15 and ubuntu20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Aug 07 2022 at 10:12):

bjorn3 commented on issue #4632:

Posting the sources inline to make it easier to see them:

(module
  (import "myenv" "sum_i32" (func $sum_i32 (param i32 i32)))

  (func $test (export "test")
    (call $sum_i32 (i32.const 0x1) (i32.const 0x2))
    (call $sum_i32 (i32.const 0x6C6C_0000) (i32.const 0x6C6C_6568))
    (call $sum_i32 (i32.const 0x6C6C_1234) (i32.const 0x1230_0000))
  )
)

//! Small example of how to instantiate a wasm module that imports one function,
//! showing how you can fill in host functionality for a wasm module.

// cargo run -q --example test

use anyhow::Result;
use wasmtime::*;


fn main() -> Result<()> {
    // Modules can be compiled through either the text or binary format
    let engine = Engine::default();
    let module = Module::from_file(&engine, "./test.wat")?;



    let mut linker = Linker::new(&engine);
    linker.func_wrap("myenv", "sum_i32", |caller: Caller<'_, u32>, x: i32, y: i32| {
        let s = x + y;
        println!("sum_i32_host Results: {:?}", s);
    })?;


    let mut store = Store::new(&engine, 4);
    let instance = linker.instantiate(&mut store, &module)?;

    println!("Extracting export...");
    let func1 = instance.get_typed_func::<(), (), _>(&mut store, "test")?;

    println!("Calling func1...");
    func1.call(&mut store, ())?;

    Ok(())
}

view this post on Zulip Wasmtime GitHub notifications bot (Aug 07 2022 at 10:22):

bjorn3 commented on issue #4632:

The error happens at the let s = x + y;. This is correct as 0x6C6C_0000 + 0x6C6C_6568 does indeed overflow. Note that this panic only happens when debug assertions are enabled as rustc compiles the addition to a wrapping addition if debug assertions are disabled. If you want to explicitly use wrapping on overflow, you can use let s = x.wrapping_add(y);.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 07 2022 at 11:45):

Zhangyx24 commented on issue #4632:

Thanks a lot !

view this post on Zulip Wasmtime GitHub notifications bot (Aug 07 2022 at 11:45):

Zhangyx24 closed issue #4632:

Test Case

test-wat.txt
test-rs.txt
test.rs is uploaded as test-rs.txt, test.wat is uploaded asa test-wat.txt.

Steps to Reproduce

cargo run -q --example test

Expected Results

sum_i32_host Results: 3
sum_i32_host Results: -656906904
sum_i32_host Results: 2124157492

Actual Results

Extracting export...
Calling func1...
sum_i32_host Results: 3
thread 'main' panicked at 'attempt to add with overflow', test.rs:24:17
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Versions and Environment

Wasmtime version or commit: 0.38.0

Operating system: macOS10.15 and ubuntu20.04

Architecture: x86_64


Last updated: Nov 22 2024 at 17:03 UTC