Report if a function isn't guaranteed to return

This commit is contained in:
dcodeIO
2018-01-19 04:16:18 +01:00
parent 7be4f9fabb
commit ef7a095494
9 changed files with 131 additions and 30 deletions

View File

@ -5,6 +5,7 @@
(export "ifThenElse" (func $if/ifThenElse))
(export "ifThen" (func $if/ifThen))
(export "ifThenElseBlock" (func $if/ifThenElse))
(export "ifAlwaysReturns" (func $if/ifAlwaysReturns))
(export "memory" (memory $0))
(start $start)
(func $if/ifThenElse (; 0 ;) (type $ii) (param $0 i32) (result i32)
@ -23,7 +24,16 @@
)
(i32.const 0)
)
(func $start (; 2 ;) (type $v)
(func $if/ifAlwaysReturns (; 2 ;) (type $ii) (param $0 i32) (result i32)
(if
(get_local $0)
(return
(i32.const 1)
)
(unreachable)
)
)
(func $start (; 3 ;) (type $v)
(if
(call $if/ifThenElse
(i32.const 0)

View File

@ -29,3 +29,10 @@ export function ifThenElseBlock(n: i32): bool {
assert(ifThenElseBlock(0) == false);
assert(ifThenElseBlock(1) == true);
export function ifAlwaysReturns(n: i32): bool {
if (n)
return true;
else
throw new Error("error");
}

View File

@ -6,6 +6,7 @@
(export "ifThenElse" (func $if/ifThenElse))
(export "ifThen" (func $if/ifThen))
(export "ifThenElseBlock" (func $if/ifThenElseBlock))
(export "ifAlwaysReturns" (func $if/ifAlwaysReturns))
(export "memory" (memory $0))
(start $start)
(func $if/ifThenElse (; 0 ;) (type $ii) (param $0 i32) (result i32)
@ -47,7 +48,16 @@
)
)
)
(func $start (; 3 ;) (type $v)
(func $if/ifAlwaysReturns (; 3 ;) (type $ii) (param $0 i32) (result i32)
(if
(get_local $0)
(return
(i32.const 1)
)
(unreachable)
)
)
(func $start (; 4 ;) (type $v)
(if
(i32.eqz
(i32.eq
@ -163,8 +173,10 @@
FUNCTION_PROTOTYPE: if/ifThenElse
FUNCTION_PROTOTYPE: if/ifThen
FUNCTION_PROTOTYPE: if/ifThenElseBlock
FUNCTION_PROTOTYPE: if/ifAlwaysReturns
[program.exports]
FUNCTION_PROTOTYPE: if/ifThenElse
FUNCTION_PROTOTYPE: if/ifThen
FUNCTION_PROTOTYPE: if/ifThenElseBlock
FUNCTION_PROTOTYPE: if/ifAlwaysReturns
;)