wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v1/testdata/traps.wast (about) 1 ;; Test that traps are preserved even in instructions which might otherwise 2 ;; be dead-code-eliminated. These functions all perform an operation and 3 ;; discard its return value. 4 5 (module 6 (func (export "no_dce.i32.div_s") (param $x i32) (param $y i32) 7 (drop (i32.div_s (local.get $x) (local.get $y)))) 8 (func (export "no_dce.i32.div_u") (param $x i32) (param $y i32) 9 (drop (i32.div_u (local.get $x) (local.get $y)))) 10 (func (export "no_dce.i64.div_s") (param $x i64) (param $y i64) 11 (drop (i64.div_s (local.get $x) (local.get $y)))) 12 (func (export "no_dce.i64.div_u") (param $x i64) (param $y i64) 13 (drop (i64.div_u (local.get $x) (local.get $y)))) 14 ) 15 16 (assert_trap (invoke "no_dce.i32.div_s" (i32.const 1) (i32.const 0)) "integer divide by zero") 17 (assert_trap (invoke "no_dce.i32.div_u" (i32.const 1) (i32.const 0)) "integer divide by zero") 18 (assert_trap (invoke "no_dce.i64.div_s" (i64.const 1) (i64.const 0)) "integer divide by zero") 19 (assert_trap (invoke "no_dce.i64.div_u" (i64.const 1) (i64.const 0)) "integer divide by zero") 20 (assert_trap (invoke "no_dce.i32.div_s" (i32.const 0x80000000) (i32.const -1)) "integer overflow") 21 (assert_trap (invoke "no_dce.i64.div_s" (i64.const 0x8000000000000000) (i64.const -1)) "integer overflow") 22 23 (module 24 (func (export "no_dce.i32.rem_s") (param $x i32) (param $y i32) 25 (drop (i32.rem_s (local.get $x) (local.get $y)))) 26 (func (export "no_dce.i32.rem_u") (param $x i32) (param $y i32) 27 (drop (i32.rem_u (local.get $x) (local.get $y)))) 28 (func (export "no_dce.i64.rem_s") (param $x i64) (param $y i64) 29 (drop (i64.rem_s (local.get $x) (local.get $y)))) 30 (func (export "no_dce.i64.rem_u") (param $x i64) (param $y i64) 31 (drop (i64.rem_u (local.get $x) (local.get $y)))) 32 ) 33 34 (assert_trap (invoke "no_dce.i32.rem_s" (i32.const 1) (i32.const 0)) "integer divide by zero") 35 (assert_trap (invoke "no_dce.i32.rem_u" (i32.const 1) (i32.const 0)) "integer divide by zero") 36 (assert_trap (invoke "no_dce.i64.rem_s" (i64.const 1) (i64.const 0)) "integer divide by zero") 37 (assert_trap (invoke "no_dce.i64.rem_u" (i64.const 1) (i64.const 0)) "integer divide by zero") 38 39 (module 40 (func (export "no_dce.i32.trunc_f32_s") (param $x f32) (drop (i32.trunc_f32_s (local.get $x)))) 41 (func (export "no_dce.i32.trunc_f32_u") (param $x f32) (drop (i32.trunc_f32_u (local.get $x)))) 42 (func (export "no_dce.i32.trunc_f64_s") (param $x f64) (drop (i32.trunc_f64_s (local.get $x)))) 43 (func (export "no_dce.i32.trunc_f64_u") (param $x f64) (drop (i32.trunc_f64_u (local.get $x)))) 44 (func (export "no_dce.i64.trunc_f32_s") (param $x f32) (drop (i64.trunc_f32_s (local.get $x)))) 45 (func (export "no_dce.i64.trunc_f32_u") (param $x f32) (drop (i64.trunc_f32_u (local.get $x)))) 46 (func (export "no_dce.i64.trunc_f64_s") (param $x f64) (drop (i64.trunc_f64_s (local.get $x)))) 47 (func (export "no_dce.i64.trunc_f64_u") (param $x f64) (drop (i64.trunc_f64_u (local.get $x)))) 48 ) 49 50 (assert_trap (invoke "no_dce.i32.trunc_f32_s" (f32.const nan)) "invalid conversion to integer") 51 (assert_trap (invoke "no_dce.i32.trunc_f32_u" (f32.const nan)) "invalid conversion to integer") 52 (assert_trap (invoke "no_dce.i32.trunc_f64_s" (f64.const nan)) "invalid conversion to integer") 53 (assert_trap (invoke "no_dce.i32.trunc_f64_u" (f64.const nan)) "invalid conversion to integer") 54 (assert_trap (invoke "no_dce.i64.trunc_f32_s" (f32.const nan)) "invalid conversion to integer") 55 (assert_trap (invoke "no_dce.i64.trunc_f32_u" (f32.const nan)) "invalid conversion to integer") 56 (assert_trap (invoke "no_dce.i64.trunc_f64_s" (f64.const nan)) "invalid conversion to integer") 57 (assert_trap (invoke "no_dce.i64.trunc_f64_u" (f64.const nan)) "invalid conversion to integer") 58 59 (module 60 (memory 1) 61 62 (func (export "no_dce.i32.load") (param $i i32) (drop (i32.load (local.get $i)))) 63 (func (export "no_dce.i32.load16_s") (param $i i32) (drop (i32.load16_s (local.get $i)))) 64 (func (export "no_dce.i32.load16_u") (param $i i32) (drop (i32.load16_u (local.get $i)))) 65 (func (export "no_dce.i32.load8_s") (param $i i32) (drop (i32.load8_s (local.get $i)))) 66 (func (export "no_dce.i32.load8_u") (param $i i32) (drop (i32.load8_u (local.get $i)))) 67 (func (export "no_dce.i64.load") (param $i i32) (drop (i64.load (local.get $i)))) 68 (func (export "no_dce.i64.load32_s") (param $i i32) (drop (i64.load32_s (local.get $i)))) 69 (func (export "no_dce.i64.load32_u") (param $i i32) (drop (i64.load32_u (local.get $i)))) 70 (func (export "no_dce.i64.load16_s") (param $i i32) (drop (i64.load16_s (local.get $i)))) 71 (func (export "no_dce.i64.load16_u") (param $i i32) (drop (i64.load16_u (local.get $i)))) 72 (func (export "no_dce.i64.load8_s") (param $i i32) (drop (i64.load8_s (local.get $i)))) 73 (func (export "no_dce.i64.load8_u") (param $i i32) (drop (i64.load8_u (local.get $i)))) 74 (func (export "no_dce.f32.load") (param $i i32) (drop (f32.load (local.get $i)))) 75 (func (export "no_dce.f64.load") (param $i i32) (drop (f64.load (local.get $i)))) 76 ) 77 78 (assert_trap (invoke "no_dce.i32.load" (i32.const 65536)) "out of bounds memory access") 79 (assert_trap (invoke "no_dce.i32.load16_s" (i32.const 65536)) "out of bounds memory access") 80 (assert_trap (invoke "no_dce.i32.load16_u" (i32.const 65536)) "out of bounds memory access") 81 (assert_trap (invoke "no_dce.i32.load8_s" (i32.const 65536)) "out of bounds memory access") 82 (assert_trap (invoke "no_dce.i32.load8_u" (i32.const 65536)) "out of bounds memory access") 83 (assert_trap (invoke "no_dce.i64.load" (i32.const 65536)) "out of bounds memory access") 84 (assert_trap (invoke "no_dce.i64.load32_s" (i32.const 65536)) "out of bounds memory access") 85 (assert_trap (invoke "no_dce.i64.load32_u" (i32.const 65536)) "out of bounds memory access") 86 (assert_trap (invoke "no_dce.i64.load16_s" (i32.const 65536)) "out of bounds memory access") 87 (assert_trap (invoke "no_dce.i64.load16_u" (i32.const 65536)) "out of bounds memory access") 88 (assert_trap (invoke "no_dce.i64.load8_s" (i32.const 65536)) "out of bounds memory access") 89 (assert_trap (invoke "no_dce.i64.load8_u" (i32.const 65536)) "out of bounds memory access") 90 (assert_trap (invoke "no_dce.f32.load" (i32.const 65536)) "out of bounds memory access") 91 (assert_trap (invoke "no_dce.f64.load" (i32.const 65536)) "out of bounds memory access")