<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[210111] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/210111">210111</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-12-22 14:19:42 -0800 (Thu, 22 Dec 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>WebAssembly: The validator should not allow unused stack entries at the end of a block
https://bugs.webkit.org/show_bug.cgi?id=166411
Reviewed by Saam Barati.
JSTests:
Test cleanup and enable new passing tests.
* wasm.yaml:
* wasm/function-tests/br-if-as-return.js:
Source/JavaScriptCore:
This patch also cleans up some of the verbose mode logging.
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::dumpExpressionStack):
(JSC::Wasm::B3IRGenerator::dump):
* wasm/WasmFunctionParser.h:
* wasm/WasmValidate.cpp:
(JSC::Wasm::dumpExpressionStack):
(JSC::Wasm::Validate::dump):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkJSTestswasmfunctiontestsbrifasreturnjs">trunk/JSTests/wasm/function-tests/br-if-as-return.js</a></li>
<li><a href="#trunkJSTestswasmyaml">trunk/JSTests/wasm.yaml</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmFunctionParserh">trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmValidatecpp">trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/JSTests/ChangeLog        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-12-22 Keith Miller <keith_miller@apple.com>
+
+ WebAssembly: The validator should not allow unused stack entries at the end of a block
+ https://bugs.webkit.org/show_bug.cgi?id=166411
+
+ Reviewed by Saam Barati.
+
+ Test cleanup and enable new passing tests.
+
+ * wasm.yaml:
+ * wasm/function-tests/br-if-as-return.js:
+
</ins><span class="cx"> 2016-12-22 Saam Barati <sbarati@apple.com>
</span><span class="cx">
</span><span class="cx"> WebAssembly: Make the spec-tests/start.wast.js test pass
</span></span></pre></div>
<a id="trunkJSTestswasmfunctiontestsbrifasreturnjs"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/wasm/function-tests/br-if-as-return.js (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm/function-tests/br-if-as-return.js        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/JSTests/wasm/function-tests/br-if-as-return.js        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -10,12 +10,11 @@
</span><span class="cx"> .End()
</span><span class="cx"> .Code()
</span><span class="cx"> .Function("br1", { params: [], ret: "i32" })
</span><del>- .Block("void", b => {
</del><ins>+ .Block("i32", b => {
</ins><span class="cx"> return b.I32Const(0)
</span><span class="cx"> .I32Const(1)
</span><span class="cx"> .BrIf(1)
</span><span class="cx"> })
</span><del>- .Unreachable()
</del><span class="cx"> .End()
</span><span class="cx">
</span><span class="cx"> .Function("br0", { params: [], ret: "i32" })
</span></span></pre></div>
<a id="trunkJSTestswasmyaml"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/wasm.yaml (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm.yaml        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/JSTests/wasm.yaml        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -35,13 +35,13 @@
</span><span class="cx"> cmd: runWebAssemblySpecTest :normal
</span><span class="cx">
</span><span class="cx"> - path: wasm/spec-tests/block.wast.js
</span><del>- cmd: runWebAssemblySpecTest :skip
</del><ins>+ cmd: runWebAssemblySpecTest :normal
</ins><span class="cx">
</span><span class="cx"> - path: wasm/spec-tests/br.wast.js
</span><span class="cx"> cmd: runWebAssemblySpecTest :normal
</span><span class="cx">
</span><span class="cx"> - path: wasm/spec-tests/br_if.wast.js
</span><del>- cmd: runWebAssemblySpecTest :skip
</del><ins>+ cmd: runWebAssemblySpecTest :normal
</ins><span class="cx">
</span><span class="cx"> - path: wasm/spec-tests/br_table.wast.js
</span><span class="cx"> cmd: runWebAssemblySpecTest :normal
</span><span class="lines">@@ -101,7 +101,7 @@
</span><span class="cx"> cmd: runWebAssemblySpecTest :normal
</span><span class="cx">
</span><span class="cx"> - path: wasm/spec-tests/func.wast.js
</span><del>- cmd: runWebAssemblySpecTest :skip
</del><ins>+ cmd: runWebAssemblySpecTest :normal
</ins><span class="cx">
</span><span class="cx"> - path: wasm/spec-tests/func_ptrs.wast.js
</span><span class="cx"> cmd: runWebAssemblySpecTest :skip
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2016-12-22 Keith Miller <keith_miller@apple.com>
+
+ WebAssembly: The validator should not allow unused stack entries at the end of a block
+ https://bugs.webkit.org/show_bug.cgi?id=166411
+
+ Reviewed by Saam Barati.
+
+ This patch also cleans up some of the verbose mode logging.
+
+ * wasm/WasmB3IRGenerator.cpp:
+ (JSC::Wasm::dumpExpressionStack):
+ (JSC::Wasm::B3IRGenerator::dump):
+ * wasm/WasmFunctionParser.h:
+ * wasm/WasmValidate.cpp:
+ (JSC::Wasm::dumpExpressionStack):
+ (JSC::Wasm::Validate::dump):
+
</ins><span class="cx"> 2016-12-22 Saam Barati <sbarati@apple.com>
</span><span class="cx">
</span><span class="cx"> WebAssembly: Make the spec-tests/start.wast.js test pass
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -199,7 +199,7 @@
</span><span class="cx"> PartialResult WARN_UNUSED_RETURN addCallIndirect(const Signature*, SignatureIndex, Vector<ExpressionType>& args, ExpressionType& result);
</span><span class="cx"> PartialResult WARN_UNUSED_RETURN addUnreachable();
</span><span class="cx">
</span><del>- void dump(const Vector<ControlEntry>& controlStack, const ExpressionList& expressionStack);
</del><ins>+ void dump(const Vector<ControlEntry>& controlStack, const ExpressionList* expressionStack);
</ins><span class="cx">
</span><span class="cx"> void emitExceptionCheck(CCallHelpers&, ExceptionType);
</span><span class="cx">
</span><span class="lines">@@ -803,28 +803,26 @@
</span><span class="cx">
</span><span class="cx"> static void dumpExpressionStack(const CommaPrinter& comma, const B3IRGenerator::ExpressionList& expressionStack)
</span><span class="cx"> {
</span><del>- dataLogLn(comma, "ExpressionStack:");
</del><ins>+ dataLog(comma, "ExpressionStack:");
</ins><span class="cx"> for (const auto& expression : expressionStack)
</span><del>- dataLogLn(comma, *expression);
</del><ins>+ dataLog(comma, *expression);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void B3IRGenerator::dump(const Vector<ControlEntry>& controlStack, const ExpressionList& expressionStack)
</del><ins>+void B3IRGenerator::dump(const Vector<ControlEntry>& controlStack, const ExpressionList* expressionStack)
</ins><span class="cx"> {
</span><span class="cx"> dataLogLn("Processing Graph:");
</span><span class="cx"> dataLog(m_proc);
</span><span class="cx"> dataLogLn("With current block:", *m_currentBlock);
</span><span class="cx"> dataLogLn("Control stack:");
</span><del>- for (auto& data : controlStack) {
- dataLogLn(" ", data.controlData);
- if (data.enclosedExpressionStack.size()) {
- CommaPrinter comma(" ", " with ");
- dumpExpressionStack(comma, data.enclosedExpressionStack);
- }
</del><ins>+ ASSERT(controlStack.size());
+ for (size_t i = controlStack.size(); i--;) {
+ dataLog(" ", controlStack[i].controlData, ": ");
+ CommaPrinter comma(", ", "");
+ dumpExpressionStack(comma, *expressionStack);
+ expressionStack = &controlStack[i].enclosedExpressionStack;
+ dataLogLn();
</ins><span class="cx"> }
</span><del>-
- CommaPrinter comma(" ", "");
- dumpExpressionStack(comma, expressionStack);
- dataLogLn("\n");
</del><ins>+ dataLogLn();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static void createJSToWasmWrapper(VM& vm, CompilationContext& compilationContext, WasmInternalFunction& function, const Signature* signature, const MemoryInformation& memory)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmFunctionParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -134,7 +134,7 @@
</span><span class="cx">
</span><span class="cx"> if (verbose) {
</span><span class="cx"> dataLogLn("processing op (", m_unreachableBlocks, "): ", RawPointer(reinterpret_cast<void*>(op)), ", ", makeString(static_cast<OpType>(op)), " at offset: ", RawPointer(reinterpret_cast<void*>(m_offset)));
</span><del>- m_context.dump(m_controlStack, m_expressionStack);
</del><ins>+ m_context.dump(m_controlStack, &m_expressionStack);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (m_unreachableBlocks)
</span><span class="lines">@@ -389,7 +389,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> case Else: {
</span><del>- WASM_PARSER_FAIL_IF(m_controlStack.isEmpty(), "can't use else block at the top-level of a function");
</del><ins>+ WASM_PARSER_FAIL_IF(m_controlStack.size() == 1, "can't use else block at the top-level of a function");
</ins><span class="cx"> WASM_TRY_ADD_TO_CONTEXT(addElse(m_controlStack.last().controlData, m_expressionStack));
</span><span class="cx"> m_expressionStack.shrink(0);
</span><span class="cx"> return { };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmValidatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp (210110 => 210111)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp        2016-12-22 21:56:50 UTC (rev 210110)
+++ trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp        2016-12-22 22:19:42 UTC (rev 210111)
</span><span class="lines">@@ -146,13 +146,12 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>- void dump(const Vector<ControlEntry>&, const ExpressionList&);
</del><ins>+ void dump(const Vector<ControlEntry>&, const ExpressionList*);
</ins><span class="cx">
</span><span class="cx"> private:
</span><del>- Result unify(Type, Type);
- Result unify(const ExpressionList&, const ControlData&);
</del><ins>+ Result WARN_UNUSED_RETURN unify(const ExpressionList&, const ControlData&);
</ins><span class="cx">
</span><del>- Result checkBranchTarget(ControlData& target, const ExpressionList& expressionStack);
</del><ins>+ Result WARN_UNUSED_RETURN checkBranchTarget(ControlData& target, const ExpressionList& expressionStack);
</ins><span class="cx">
</span><span class="cx"> Vector<Type> m_locals;
</span><span class="cx"> const ModuleInformation& m_module;
</span><span class="lines">@@ -295,16 +294,8 @@
</span><span class="cx">
</span><span class="cx"> auto Validate::endBlock(ControlEntry& entry, ExpressionList& stack) -> Result
</span><span class="cx"> {
</span><del>- ControlData& block = entry.controlData;
- if (block.signature() == Void)
- return { };
-
- WASM_VALIDATOR_FAIL_IF(block.type() == BlockType::If, "If-block had a non-void result type: ", block.signature(), " but had no else-block");
- WASM_VALIDATOR_FAIL_IF(stack.isEmpty(), "typed block falls through on empty stack");
- WASM_VALIDATOR_FAIL_IF(block.signature() != stack.last(), "block fallthrough doesn't match its declared type");
-
- entry.enclosedExpressionStack.append(block.signature());
- return { };
</del><ins>+ WASM_FAIL_IF_HELPER_FAILS(unify(stack, entry.controlData));
+ return addEndToUnreachable(entry);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> auto Validate::addEndToUnreachable(ControlEntry& entry) -> Result
</span><span class="lines">@@ -346,22 +337,35 @@
</span><span class="cx">
</span><span class="cx"> auto Validate::unify(const ExpressionList& values, const ControlType& block) -> Result
</span><span class="cx"> {
</span><del>- ASSERT(values.size() <= 1);
- if (block.signature() == Void)
</del><ins>+ if (block.signature() == Void) {
+ WASM_VALIDATOR_FAIL_IF(!values.isEmpty(), "void block should end with an empty stack");
</ins><span class="cx"> return { };
</span><ins>+ }
</ins><span class="cx">
</span><del>- WASM_VALIDATOR_FAIL_IF(values.isEmpty(), "non-void block ends with an empty stack");
</del><ins>+ WASM_VALIDATOR_FAIL_IF(values.size() != 1, "block with type: ", block.signature(), " ends with a stack containing more than one value");
</ins><span class="cx"> WASM_VALIDATOR_FAIL_IF(values[0] != block.signature(), "control flow returns with unexpected type");
</span><del>-
</del><span class="cx"> return { };
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Validate::dump(const Vector<ControlEntry>&, const ExpressionList&)
</del><ins>+static void dumpExpressionStack(const CommaPrinter& comma, const Validate::ExpressionList& expressionStack)
</ins><span class="cx"> {
</span><del>- // If you need this then you should fix the validator's error messages instead...
- // Think of this as penance for the sin of bad error messages.
</del><ins>+ dataLog(comma, " ExpressionStack:");
+ for (const auto& expression : expressionStack)
+ dataLog(comma, makeString(expression));
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void Validate::dump(const Vector<ControlEntry>& controlStack, const ExpressionList* expressionStack)
+{
+ for (size_t i = controlStack.size(); i--;) {
+ dataLog(" ", controlStack[i].controlData);
+ CommaPrinter comma(", ", "");
+ dumpExpressionStack(comma, *expressionStack);
+ expressionStack = &controlStack[i].enclosedExpressionStack;
+ dataLogLn();
+ }
+ dataLogLn();
+}
+
</ins><span class="cx"> Expected<void, String> validateFunction(VM* vm, const uint8_t* source, size_t length, const Signature* signature, const ImmutableFunctionIndexSpace& functionIndexSpace, const ModuleInformation& module)
</span><span class="cx"> {
</span><span class="cx"> Validate context(module);
</span></span></pre>
</div>
</div>
</body>
</html>