diff options
29 files changed, 65 insertions, 57 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 4b5df766d..3096ada07 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -362,6 +362,7 @@ public: ret->ptr = ptr; ret->type = type; ret->memory = memory; + ret->finalize(); return ret; } Load* makeAtomicLoad( diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index f8c8cf0a0..8098856e4 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -677,6 +677,9 @@ Result<Expression*> IRBuilder::finishScope(Block* block) { } else { auto hoisted = hoistLastValue(); CHECK_ERR(hoisted); + if (!hoisted) { + return Err{"popping from empty stack"}; + } auto hoistedType = scope.exprStack.back()->type; if (hoistedType.size() != type.size()) { // We cannot propagate the hoisted value directly because it does not diff --git a/test/ctor-eval/bad-indirect-call2.wast b/test/ctor-eval/bad-indirect-call2.wast index 60d73b7fc..4f2d350ca 100644 --- a/test/ctor-eval/bad-indirect-call2.wast +++ b/test/ctor-eval/bad-indirect-call2.wast @@ -1,8 +1,8 @@ (module + (import "env" "_abort" (func $_abort)) (type $v (func)) (memory 256 256) (data (i32.const 10) "waka waka waka waka waka") - (import "env" "_abort" (func $_abort)) (table 2 2 funcref) (elem (i32.const 0) $_abort $call-indirect) (export "test1" (func $test1)) diff --git a/test/ctor-eval/imported-global-2.wast b/test/ctor-eval/imported-global-2.wast index 0662fb760..f1dfc6828 100644 --- a/test/ctor-eval/imported-global-2.wast +++ b/test/ctor-eval/imported-global-2.wast @@ -1,9 +1,9 @@ (module - (memory 256 256) - ;; imports must not be used (import "env" "imported" (global $imported i32)) + (memory 256 256) + (func $test1 (export "test1") (result i32) (local $temp i32) diff --git a/test/ctor-eval/imported-global.wast b/test/ctor-eval/imported-global.wast index 1c14a3114..edc1f48ff 100644 --- a/test/ctor-eval/imported-global.wast +++ b/test/ctor-eval/imported-global.wast @@ -1,8 +1,8 @@ (module + (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) (memory 256 256) (data (i32.const 10) "waka waka waka waka waka") ;; imports must not be used - (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) (export "test1" (func $test1)) (global $mine (mut i32) (global.get $tempDoublePtr)) ;; BAD, if used (func $test1 diff --git a/test/ctor-eval/indirect-call3.wast b/test/ctor-eval/indirect-call3.wast index 0c18c01d5..1c01513b1 100644 --- a/test/ctor-eval/indirect-call3.wast +++ b/test/ctor-eval/indirect-call3.wast @@ -1,8 +1,8 @@ (module + (import "env" "_abort" (func $_abort)) (type $v (func)) (memory 256 256) (data (i32.const 10) "waka waka waka waka waka") - (import "env" "_abort" (func $_abort)) (table 2 2 funcref) (elem (i32.const 0) $_abort $call-indirect) (export "test1" (func $test1)) diff --git a/test/lit/passes/vacuum_all-features.wast b/test/lit/passes/vacuum_all-features.wast index 5dbbb9386..636814f3d 100644 --- a/test/lit/passes/vacuum_all-features.wast +++ b/test/lit/passes/vacuum_all-features.wast @@ -4,7 +4,6 @@ ;; RUN: foreach %s %t wasm-opt --vacuum --all-features -S -o - | filecheck %s (module - (memory 256 256) ;; CHECK: (type $0 (func)) (type $0 (func)) ;; CHECK: (type $3 (func (result i32))) @@ -16,14 +15,18 @@ (type $3 (func (result i32))) ;; CHECK: (type $4 (func (param i32 f64 i32 i32))) (type $4 (func (param i32 f64 i32 i32))) + ;; CHECK: (type $5 (func (param i32) (result i32))) ;; CHECK: (type $6 (func (result f64))) ;; CHECK: (import "env" "int" (func $int (type $3) (result i32))) (import "env" "int" (func $int (result i32))) + ;; CHECK: (global $Int i32 (i32.const 0)) (global $Int i32 (i32.const 0)) + + (memory 256 256) ;; CHECK: (memory $0 256 256) ;; CHECK: (func $b (type $0) diff --git a/test/lit/validation/closed-world-interface.wast b/test/lit/validation/closed-world-interface.wast index daedaf990..19b0faa10 100644 --- a/test/lit/validation/closed-world-interface.wast +++ b/test/lit/validation/closed-world-interface.wast @@ -39,29 +39,29 @@ (type $private (func (param v128))) - (func $1 (export "test1") (type $void) + ;; Ok even though it is an import instead of an export. + (func $1 (import "env" "test5") (type $exported-pair-1)) + + (func $2 (export "test1") (type $void) (unreachable) ) ;; Ok because it only refers to basic heap types - (func $2 (export "test2") (type $abstract) + (func $3 (export "test2") (type $abstract) (unreachable) ) ;; Not ok because it refers to $struct. - (func $3 (export "test3") (type $concrete) + (func $4 (export "test3") (type $concrete) (unreachable) ) ;; Ok even though it is in a rec group because the rest of the group and the ;; types this refers to are on the boundary as well. - (func $4 (export "test4") (type $exported-pair-0) + (func $5 (export "test4") (type $exported-pair-0) (unreachable) ) - ;; Ok even though it is an import instead of an export. - (func $5 (import "env" "test5") (type $exported-pair-1)) - ;; Ok, and we also allow the other type in the group. (func $6 (export "test6") (type $partial-pair-0) (unreachable) diff --git a/test/lit/validation/extended-const.wast b/test/lit/validation/extended-const.wast index 9317f47b7..6b506671f 100644 --- a/test/lit/validation/extended-const.wast +++ b/test/lit/validation/extended-const.wast @@ -17,8 +17,8 @@ ;; EXTENDED: ) "hello world") (module - (memory 1 1) (import "env" "global" (global i32)) + (memory 1 1) (global i32 (i32.add (global.get 0) (i32.const 42))) - (data (i32.sub (global.get 0) (i32.const 10)) "hello world") + (data (offset (i32.sub (global.get 0) (i32.const 10))) "hello world") ) diff --git a/test/lit/wasm-split/export-name-already-exists.wast b/test/lit/wasm-split/export-name-already-exists.wast index 83951795a..a83055da1 100644 --- a/test/lit/wasm-split/export-name-already-exists.wast +++ b/test/lit/wasm-split/export-name-already-exists.wast @@ -4,6 +4,6 @@ ;; CHECK: error: Export foo already exists. (module - (memory 0 0) - (export "foo" (memory 0 0)) + (memory $m 0 0) + (export "foo" (memory $m)) ) diff --git a/test/lit/wasm-split/merge-profiles.wast b/test/lit/wasm-split/merge-profiles.wast index 2d09fefaa..1bd9c8a4a 100644 --- a/test/lit/wasm-split/merge-profiles.wast +++ b/test/lit/wasm-split/merge-profiles.wast @@ -22,8 +22,8 @@ ;; SPLIT-NEXT: Splitting out functions: qux{{$}} (module - (memory 0 0) - (export "memory" (memory 0 0)) + (memory $m 0 0) + (export "memory" (memory $m)) (export "foo" (func $foo)) (export "bar" (func $bar)) (export "baz" (func $baz)) diff --git a/test/lit/wasm-split/mismatched-hashes.wast b/test/lit/wasm-split/mismatched-hashes.wast index 347fb1746..8f2bd69fe 100644 --- a/test/lit/wasm-split/mismatched-hashes.wast +++ b/test/lit/wasm-split/mismatched-hashes.wast @@ -19,6 +19,6 @@ ;; RUN: wasm-split %s --profile=%t.prof -o1 %t.1.wasm -o2 %t.2.wasm (module - (memory 0 0) - (export "memory" (memory 0 0)) + (memory $m 0 0) + (export "memory" (memory $m)) ) diff --git a/test/lit/wasm-split/print-profile.wast b/test/lit/wasm-split/print-profile.wast index cea701629..ec37858bd 100644 --- a/test/lit/wasm-split/print-profile.wast +++ b/test/lit/wasm-split/print-profile.wast @@ -15,8 +15,8 @@ ;; UNESCAPED: - bar(double[3]) (module - (memory 0 0) - (export "memory" (memory 0 0)) + (memory $m 0 0) + (export "memory" (memory $m)) (export "foo" (func $foo)) (export "bar" (func $bar\28double\5b3\5d\29)) (func $foo diff --git a/test/metadce/corners.wast b/test/metadce/corners.wast index 4f9c17564..c9b8de628 100644 --- a/test/metadce/corners.wast +++ b/test/metadce/corners.wast @@ -1,9 +1,6 @@ (module (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) - (global $STACKTOP (mut i32) (global.get $STACKTOP$asm2wasm$import)) - (import "env" "UNUSEDTOP" (global $UNUSEDTOP$asm2wasm$import i32)) - (global $UNUSEDTOP (mut i32) (global.get $UNUSEDTOP$asm2wasm$import)) (import "env" "imported_twice" (func $imported_twice_a)) ;; and used just once, (import "env" "imported_twice" (func $imported_twice_b)) ;; but the other should not kill the import for both! @@ -11,6 +8,10 @@ (import "env" "an-imported-table-func" (func $imported_table_func)) (import "env" "table" (table 10 10 funcref)) + + (global $STACKTOP (mut i32) (global.get $STACKTOP$asm2wasm$import)) + (global $UNUSEDTOP (mut i32) (global.get $UNUSEDTOP$asm2wasm$import)) + (elem (i32.const 0) $imported_table_func) (export "stackAlloc" (func $stackAlloc)) @@ -20,4 +21,3 @@ (call $imported_twice_a) ) ) - diff --git a/test/metadce/outside.wast b/test/metadce/outside.wast index 14e871fb6..487443a0e 100644 --- a/test/metadce/outside.wast +++ b/test/metadce/outside.wast @@ -4,14 +4,15 @@ (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 10 10 funcref)) + (global $from_segment (import "env" "g1") i32) + (global $from_segment_2 (import "env" "g2") i32) + (global $from_segment_never_used (import "env" "g3") i32) + (export "wasm_func" (func $a_wasm_func)) (export "wasm_func_unused" (func $an_unused_wasm_func)) (global $__THREW__ (mut i32) (i32.const 0)) (global $__THREW__unused (mut i32) (i32.const 0)) - (global $from_segment (import "env" "g1") i32) - (global $from_segment_2 (import "env" "g2") i32) - (global $from_segment_never_used (import "env" "g3") i32) (data (i32.const 1024) "abcd") (data (global.get $from_segment) "abcd") diff --git a/test/metadce/spanning_cycle.wast b/test/metadce/spanning_cycle.wast index e433227dc..381b2d246 100644 --- a/test/metadce/spanning_cycle.wast +++ b/test/metadce/spanning_cycle.wast @@ -1,8 +1,9 @@ (module + (import "env" "js_func" (func $a_js_func)) + (memory 1 1) - (data "Hello, datacount section!") - (import "env" "js_func" (func $a_js_func)) + (data "Hello, datacount section!") (export "wasm_func_a" (func $a_wasm_func)) diff --git a/test/passes/duplicate-function-elimination_optimize-level=1.wast b/test/passes/duplicate-function-elimination_optimize-level=1.wast index 1097f6715..c66cfba5d 100644 --- a/test/passes/duplicate-function-elimination_optimize-level=1.wast +++ b/test/passes/duplicate-function-elimination_optimize-level=1.wast @@ -435,10 +435,10 @@ ) ) (module - (memory 0) - (type $FUNCSIG$v (func)) (import "env" "i" (func $i)) (import "env" "j" (func $j)) + (memory 0) + (type $FUNCSIG$v (func)) (func $erase (type $FUNCSIG$v) (call $i) ) @@ -447,10 +447,10 @@ ) ) (module - (memory 0) - (type $FUNCSIG$v (func)) (import "env" "i" (func $i)) (import "env" "j" (func $j)) + (memory 0) + (type $FUNCSIG$v (func)) (func $keep2 (type $FUNCSIG$v) (call $i) ) diff --git a/test/passes/duplicate-function-elimination_optimize-level=2.wast b/test/passes/duplicate-function-elimination_optimize-level=2.wast index 1097f6715..c66cfba5d 100644 --- a/test/passes/duplicate-function-elimination_optimize-level=2.wast +++ b/test/passes/duplicate-function-elimination_optimize-level=2.wast @@ -435,10 +435,10 @@ ) ) (module - (memory 0) - (type $FUNCSIG$v (func)) (import "env" "i" (func $i)) (import "env" "j" (func $j)) + (memory 0) + (type $FUNCSIG$v (func)) (func $erase (type $FUNCSIG$v) (call $i) ) @@ -447,10 +447,10 @@ ) ) (module - (memory 0) - (type $FUNCSIG$v (func)) (import "env" "i" (func $i)) (import "env" "j" (func $j)) + (memory 0) + (type $FUNCSIG$v (func)) (func $keep2 (type $FUNCSIG$v) (call $i) ) diff --git a/test/passes/remove-imports.wast b/test/passes/remove-imports.wast index 77c16e991..e3a360d45 100644 --- a/test/passes/remove-imports.wast +++ b/test/passes/remove-imports.wast @@ -1,5 +1,4 @@ (module - (memory 1024 1024) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$d (func (result f64))) @@ -9,6 +8,7 @@ (import "somewhere" "waka-sneaky" (func $waka-sneaky)) (import "env" "memBase" (global i32)) (import "env" "table" (table $table 1 1 funcref)) + (memory 1024 1024) (elem (i32.const 0) $waka-sneaky) (func $nada (type $FUNCSIG$v) (call $waka) diff --git a/test/passes/remove-unused-nonfunction-module-elements_all-features.wast b/test/passes/remove-unused-nonfunction-module-elements_all-features.wast index 2917b23a0..dd37822c0 100644 --- a/test/passes/remove-unused-nonfunction-module-elements_all-features.wast +++ b/test/passes/remove-unused-nonfunction-module-elements_all-features.wast @@ -275,9 +275,9 @@ ) (module ;; non-exported tags can be removed (type $0 (func (param i32))) + (import "env" "e" (tag $e2 (param i32))) (tag $e0 (type $0)) (tag $e1 (param i64)) (export "e1" (tag $e1)) - (import "env" "e" (tag $e2 (param i32))) (func $f (; 0 ;) (type $0)) ) diff --git a/test/passes/safe-heap_disable-simd.wast b/test/passes/safe-heap_disable-simd.wast index f867a0e7c..6aa612230 100644 --- a/test/passes/safe-heap_disable-simd.wast +++ b/test/passes/safe-heap_disable-simd.wast @@ -2,8 +2,8 @@ (memory 1 1) ) (module - (memory 1 1) (import "env" "emscripten_get_sbrk_ptr" (func $foo (result i32))) + (memory 1 1) ) (module (memory 1 1) diff --git a/test/passes/simplify-locals_all-features.wast b/test/passes/simplify-locals_all-features.wast index e51abda5c..47bb7f1b5 100644 --- a/test/passes/simplify-locals_all-features.wast +++ b/test/passes/simplify-locals_all-features.wast @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) @@ -13,6 +12,7 @@ (import "env" "moddi" (func $___udivmoddi4 (param i32 i32 i32 i32 i32) (result i32))) (import "env" "lp" (func $lp (param i32 i32) (result i32))) (import "fuzzing-support" "log-f32" (func $fimport$0 (param f32))) + (memory 256 256) (global $global$0 (mut i32) (i32.const 10)) (func $contrast ;; check for tee and structure sinking (local $x i32) @@ -1187,7 +1187,6 @@ ) ) (module - (memory 256 256 shared) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) @@ -1198,6 +1197,7 @@ (import "fuzzing-support" "log1" (func $fimport$0 (result i32))) (import "fuzzing-support" "log2" (func $fimport$1 (param i32))) (import "fuzzing-support" "log3" (func $fimport$2 (param f32))) + (memory 256 256 shared) (global $global$0 (mut i32) (i32.const 10)) (func $nonatomics (result i32) ;; loads are reordered (local $x i32) diff --git a/test/passes/simplify-locals_all-features_disable-exception-handling.wast b/test/passes/simplify-locals_all-features_disable-exception-handling.wast index 9fa89ea20..0fc110696 100644 --- a/test/passes/simplify-locals_all-features_disable-exception-handling.wast +++ b/test/passes/simplify-locals_all-features_disable-exception-handling.wast @@ -1,5 +1,4 @@ (module - (memory 256 256) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) @@ -13,6 +12,7 @@ (import "env" "moddi" (func $___udivmoddi4 (param i32 i32 i32 i32 i32) (result i32))) (import "env" "lp" (func $lp (param i32 i32) (result i32))) (import "fuzzing-support" "log-f32" (func $fimport$0 (param f32))) + (memory 256 256) (global $global$0 (mut i32) (i32.const 10)) (func $contrast ;; check for tee and structure sinking (local $x i32) @@ -1187,7 +1187,6 @@ ) ) (module - (memory 256 256 shared) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) @@ -1198,6 +1197,7 @@ (import "fuzzing-support" "log1" (func $fimport$0 (result i32))) (import "fuzzing-support" "log2" (func $fimport$1 (param i32))) (import "fuzzing-support" "log3" (func $fimport$2 (param f32))) + (memory 256 256 shared) (global $global$0 (mut i32) (i32.const 10)) (func $nonatomics (result i32) ;; loads are reordered (local $x i32) diff --git a/test/passes/spill-pointers.wast b/test/passes/spill-pointers.wast index 4a9d71f14..b9c59b2c5 100644 --- a/test/passes/spill-pointers.wast +++ b/test/passes/spill-pointers.wast @@ -1,10 +1,10 @@ (module + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "segfault" (func $segfault (param i32))) (memory 10) (type $ii (func (param i32 i32))) (table 1 1 funcref) (elem (i32.const 0)) - (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) - (import "env" "segfault" (func $segfault (param i32))) (global $stack_ptr (mut i32) (global.get $STACKTOP$asm2wasm$import)) (func $nothing @@ -171,13 +171,13 @@ ) (module + (import "env" "segfault" (func $segfault (param i32))) (memory 10) (type $ii (func (param i32 i32))) (table 1 1 funcref) (elem (i32.const 0)) (global $stack_ptr (mut i32) (i32.const 1716592)) (export "stackSave" (func $stack_save)) - (import "env" "segfault" (func $segfault (param i32))) (func $stack_save (result i32) (global.get $stack_ptr) ) diff --git a/test/unit/input/asyncify-coroutine.wat b/test/unit/input/asyncify-coroutine.wat index 1d46c1269..5e33f10d2 100644 --- a/test/unit/input/asyncify-coroutine.wat +++ b/test/unit/input/asyncify-coroutine.wat @@ -1,8 +1,8 @@ (module - (memory 1 2) ;; import a "yield" function that receives the current value, ;; then pauses execution until it is resumed later. (import "env" "yield" (func $yield (param i32))) + (memory 1 2) (export "memory" (memory 0)) ;; simple linear progression in a loop (func $linear (export "linear") (result i32) diff --git a/test/unit/input/asyncify-pure.wat b/test/unit/input/asyncify-pure.wat index 671a6cf24..be9743df8 100644 --- a/test/unit/input/asyncify-pure.wat +++ b/test/unit/input/asyncify-pure.wat @@ -1,10 +1,10 @@ (module - (memory 1 1) (import "spectest" "print" (func $print (param i32))) (import "asyncify" "start_unwind" (func $asyncify_start_unwind (param i32))) (import "asyncify" "stop_unwind" (func $asyncify_stop_unwind)) (import "asyncify" "start_rewind" (func $asyncify_start_rewind (param i32))) (import "asyncify" "stop_rewind" (func $asyncify_stop_rewind)) + (memory 1 1) (global $sleeping (mut i32) (i32.const 0)) (start $runtime) (func $main @@ -63,4 +63,3 @@ (func $DOS_ReadFile\28unsigned\20short\2c\20unsigned\20char*\2c\20unsigned\20short*\2c\20bool\29 (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) ) ) - diff --git a/test/unit/input/asyncify-sleep.wat b/test/unit/input/asyncify-sleep.wat index 8c31408da..5843f4e3f 100644 --- a/test/unit/input/asyncify-sleep.wat +++ b/test/unit/input/asyncify-sleep.wat @@ -1,8 +1,8 @@ (module - (memory 1 2) - (type $ii (func (param i32) (result i32))) (import "env" "sleep" (func $sleep)) (import "env" "tunnel" (func $tunnel (param $x i32) (result i32))) + (memory 1 2) + (type $ii (func (param i32) (result i32))) (export "memory" (memory 0)) (export "factorial-recursive" (func $factorial-recursive)) (global $temp (mut i32) (i32.const 0)) diff --git a/test/unit/input/asyncify-stackOverflow.wat b/test/unit/input/asyncify-stackOverflow.wat index b838f2360..8be4c59f1 100644 --- a/test/unit/input/asyncify-stackOverflow.wat +++ b/test/unit/input/asyncify-stackOverflow.wat @@ -1,6 +1,6 @@ (module - (memory 1 2) (import "env" "sleep" (func $sleep)) + (memory 1 2) (export "memory" (memory 0)) (func $many_locals (export "many_locals") (param $x i32) (result i32) (local $y i32) diff --git a/test/unit/test_features.py b/test/unit/test_features.py index 2c596a542..4ce426275 100644 --- a/test/unit/test_features.py +++ b/test/unit/test_features.py @@ -177,7 +177,7 @@ class FeatureValidationTest(utils.BinaryenTestCase): (module (import "env" "test1" (func $test1 (param externref) (result externref))) (import "env" "test2" (global $test2 externref)) - (export "test1" (func $test1 (param externref) (result externref))) + (export "test1" (func $test1)) (export "test2" (global $test2)) (func $externref_test (param $0 externref) (result externref) (return |