diff --git a/src/module.ts b/src/module.ts index de023745..3cd49751 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1746,13 +1746,8 @@ export class BinaryModule { /** Tests if an expression needs an explicit 'unreachable' when it is the terminating statement. */ export function needsExplicitUnreachable(expr: ExpressionRef): bool { // not applicable if pushing a value to the stack - switch (_BinaryenExpressionGetType(expr)) { - case NativeType.I32: - case NativeType.I64: - case NativeType.F32: - case NativeType.F64: - case NativeType.V128: return false; - } + if (_BinaryenExpressionGetType(expr) != NativeType.Unreachable) return false; + switch (_BinaryenExpressionGetId(expr)) { case ExpressionId.Unreachable: case ExpressionId.Return: return false; diff --git a/tests/compiler/function.ts b/tests/compiler/function.ts index 4c974e60..9f74a3cd 100644 --- a/tests/compiler/function.ts +++ b/tests/compiler/function.ts @@ -1,35 +1,41 @@ -function v(): void {} +function _(): void {} +function v(): void { return; } function i(): i32 { return 0; } -function I(): i64 { return 0; } +function j(): i64 { return 0; } function f(): f32 { return 0; } -function F(): f64 { return 0; } +function d(): f64 { return 0; } +_(); v(); i(); -I(); +j(); f(); -F(); +d(); -function iv(a: i32): void {} +function i_(a: i32): void {} +function iv(a: i32): void { return; } function ii(a: i32): i32 { return a; } -function II(a: i64): i64 { return a; } +function jj(a: i64): i64 { return a; } function ff(a: f32): f32 { return a; } -function FF(a: f64): f64 { return a; } +function dd(a: f64): f64 { return a; } +i_(0); iv(0); ii(0); -II(0); +jj(0); ff(0); -FF(0); +dd(0); -function iiv(a: i32, b: i32): void {} +function ii_(a: i32, b: i32): void {} +function iiv(a: i32, b: i32): void { return; } function iii(a: i32, b: i32): i32 { return a + b; } -function III(a: i64, b: i32): i64 { return a + b; } +function jjj(a: i64, b: i32): i64 { return a + b; } function fff(a: f32, b: f32): f32 { return a + b; } -function FFF(a: f64, b: f64): f64 { return a + b; } +function ddd(a: f64, b: f64): f64 { return a + b; } +ii_(1, 2); iiv(1, 2); iii(1, 2); -III(1, 2); +jjj(1, 2); fff(1, 2); -FFF(1, 2); +ddd(1, 2); diff --git a/tests/compiler/function.untouched.wat b/tests/compiler/function.untouched.wat index 9a4dc08e..b76f67e9 100644 --- a/tests/compiler/function.untouched.wat +++ b/tests/compiler/function.untouched.wat @@ -21,86 +21,101 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $function/v (; 0 ;) (type $FUNCSIG$v) + (func $function/_ (; 0 ;) (type $FUNCSIG$v) nop ) - (func $function/i (; 1 ;) (type $FUNCSIG$i) (result i32) + (func $function/v (; 1 ;) (type $FUNCSIG$v) + nop + ) + (func $function/i (; 2 ;) (type $FUNCSIG$i) (result i32) i32.const 0 ) - (func $function/I (; 2 ;) (type $FUNCSIG$j) (result i64) + (func $function/j (; 3 ;) (type $FUNCSIG$j) (result i64) i64.const 0 ) - (func $function/f (; 3 ;) (type $FUNCSIG$f) (result f32) + (func $function/f (; 4 ;) (type $FUNCSIG$f) (result f32) f32.const 0 ) - (func $function/F (; 4 ;) (type $FUNCSIG$d) (result f64) + (func $function/d (; 5 ;) (type $FUNCSIG$d) (result f64) f64.const 0 ) - (func $function/iv (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $function/i_ (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $function/ii (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - ) - (func $function/II (; 7 ;) (type $FUNCSIG$jj) (param $0 i64) (result i64) - local.get $0 - ) - (func $function/ff (; 8 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) - local.get $0 - ) - (func $function/FF (; 9 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) - local.get $0 - ) - (func $function/iiv (; 10 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $function/iv (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $function/iii (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $function/ii (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $function/jj (; 9 ;) (type $FUNCSIG$jj) (param $0 i64) (result i64) + local.get $0 + ) + (func $function/ff (; 10 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + local.get $0 + ) + (func $function/dd (; 11 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + local.get $0 + ) + (func $function/ii_ (; 12 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + nop + ) + (func $function/iiv (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + nop + ) + (func $function/iii (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.add ) - (func $function/III (; 12 ;) (type $FUNCSIG$jji) (param $0 i64) (param $1 i32) (result i64) + (func $function/jjj (; 15 ;) (type $FUNCSIG$jji) (param $0 i64) (param $1 i32) (result i64) local.get $0 local.get $1 i64.extend_i32_s i64.add ) - (func $function/fff (; 13 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) + (func $function/fff (; 16 ;) (type $FUNCSIG$fff) (param $0 f32) (param $1 f32) (result f32) local.get $0 local.get $1 f32.add ) - (func $function/FFF (; 14 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) + (func $function/ddd (; 17 ;) (type $FUNCSIG$ddd) (param $0 f64) (param $1 f64) (result f64) local.get $0 local.get $1 f64.add ) - (func $start:function (; 15 ;) (type $FUNCSIG$v) + (func $start:function (; 18 ;) (type $FUNCSIG$v) + call $function/_ call $function/v call $function/i drop - call $function/I + call $function/j drop call $function/f drop - call $function/F + call $function/d drop i32.const 0 + call $function/i_ + i32.const 0 call $function/iv i32.const 0 call $function/ii drop i64.const 0 - call $function/II + call $function/jj drop f32.const 0 call $function/ff drop f64.const 0 - call $function/FF + call $function/dd drop i32.const 1 i32.const 2 + call $function/ii_ + i32.const 1 + i32.const 2 call $function/iiv i32.const 1 i32.const 2 @@ -108,7 +123,7 @@ drop i64.const 1 i32.const 2 - call $function/III + call $function/jjj drop f32.const 1 f32.const 2 @@ -116,12 +131,12 @@ drop f64.const 1 f64.const 2 - call $function/FFF + call $function/ddd drop ) - (func $start (; 16 ;) (type $FUNCSIG$v) + (func $start (; 19 ;) (type $FUNCSIG$v) call $start:function ) - (func $null (; 17 ;) (type $FUNCSIG$v) + (func $null (; 20 ;) (type $FUNCSIG$v) ) )