WebAssembly: Allow br, br_if, and br_table to act as a return
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Dec 2016 01:06:20 +0000 (01:06 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Dec 2016 01:06:20 +0000 (01:06 +0000)
commitb1ceddcf9e654c64e41a6858066df68759137a70
tree75fd8318220ad0877fbec998c7edfc9652088366
parent1c6e9798f7620454ccadc438b599d4412d8c366a
WebAssembly: Allow br, br_if, and br_table to act as a return
https://bugs.webkit.org/show_bug.cgi?id=166393

Reviewed by Saam Barati.

JSTests:

Add tests for breaks acting as returns and fix tests that
validate error messages.

* wasm/function-tests/br-as-return.js: Added.
* wasm/function-tests/br-if-as-return.js: Added.
* wasm/function-tests/br-table-as-return.js: Added.
* wasm/function-tests/if-no-else-non-void.js:
* wasm/function-tests/struct.js: Added.
* wasm/js-api/global-error.js:
(assert.throws):
* wasm/js-api/table.js:
(assert.throws):

Source/JavaScriptCore:

This patch allows br, br_if, and br_table to treat branching to
the size of the control stack to act as a return. This change was
made by adding a new block type to the wasm function parser,
TopLevel. Adding this new block eliminates a lot of the special
case code we had in the parser previously. The only special case
we need is when the end opcode is parsed from the top level.  The
B3 IR generator needs to automatically emit a return at that
point.

Also, this patch adds the function number to validation errors
in the function parser. The current error message is not helpful
otherwise.

* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::ControlData::dump):
(JSC::Wasm::B3IRGenerator::addTopLevel):
* wasm/WasmFunctionParser.h:
* wasm/WasmPlan.cpp:
(JSC::Wasm::Plan::parseAndValidateModule):
(JSC::Wasm::Plan::run):
* wasm/WasmValidate.cpp:
(JSC::Wasm::Validate::ControlData::dump):
(JSC::Wasm::Validate::Validate):
(JSC::Wasm::Validate::addTopLevel):
(JSC::Wasm::validateFunction):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210090 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
JSTests/ChangeLog
JSTests/wasm/function-tests/br-as-return.js [new file with mode: 0644]
JSTests/wasm/function-tests/br-if-as-return.js [new file with mode: 0644]
JSTests/wasm/function-tests/br-table-as-return.js [new file with mode: 0644]
JSTests/wasm/function-tests/if-no-else-non-void.js
JSTests/wasm/function-tests/struct.js [new file with mode: 0644]
JSTests/wasm/js-api/global-error.js
JSTests/wasm/js-api/table.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Source/JavaScriptCore/wasm/WasmFunctionParser.h
Source/JavaScriptCore/wasm/WasmPlan.cpp
Source/JavaScriptCore/wasm/WasmValidate.cpp