- Revision
- 209668
- Author
- [email protected]
- Date
- 2016-12-10 11:14:51 -0800 (Sat, 10 Dec 2016)
Log Message
Fix indirect_call if the result type is used.
https://bugs.webkit.org/show_bug.cgi?id=165727
Reviewed by Michael Saboff.
JSTests:
* wasm/js-api/call-indirect-results.js: Added.
(const.wasmModuleWhichImportJS):
(MonomorphicImport):
Source/_javascript_Core:
The patchpoint for indirect_call assumed that the callee would be
in params[0]. This is not the case, however, if the callee returns
a value.
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::addCallIndirect):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (209667 => 209668)
--- trunk/JSTests/ChangeLog 2016-12-10 18:32:45 UTC (rev 209667)
+++ trunk/JSTests/ChangeLog 2016-12-10 19:14:51 UTC (rev 209668)
@@ -1,3 +1,14 @@
+2016-12-10 Keith Miller <[email protected]>
+
+ Fix indirect_call if the result type is used.
+ https://bugs.webkit.org/show_bug.cgi?id=165727
+
+ Reviewed by Michael Saboff.
+
+ * wasm/js-api/call-indirect-results.js: Added.
+ (const.wasmModuleWhichImportJS):
+ (MonomorphicImport):
+
2016-12-10 Yusuke Suzuki <[email protected]>
[JSC] Module namespace object behaves like immutable prototype exotic object
Added: trunk/JSTests/wasm/js-api/call-indirect-results.js (0 => 209668)
--- trunk/JSTests/wasm/js-api/call-indirect-results.js (rev 0)
+++ trunk/JSTests/wasm/js-api/call-indirect-results.js 2016-12-10 19:14:51 UTC (rev 209668)
@@ -0,0 +1,41 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const wasmModuleWhichImportJS = () => {
+ const builder = (new Builder())
+ .Type().End()
+ .Import()
+ .Function("imp", "func", { params: ["i32"], ret: "i32" })
+ .End()
+ .Function().End()
+ .Export()
+ .Function("changeCounter")
+ .End()
+ .Code()
+ .Function("changeCounter", { params: ["i32", "i32"], ret: "i32" })
+ .I32Const(42)
+ .GetLocal(0)
+ .I32Add()
+ .GetLocal(1)
+ .CallIndirect(0, 0) // Calls func(param[0] + 42).
+ .I32Const(0)
+ .CallIndirect(0, 0) // Calls func(param[0] + 42).
+ .End()
+ .End();
+ const bin = builder.WebAssembly().get();
+ const module = new WebAssembly.Module(bin);
+ return module;
+};
+
+
+(function MonomorphicImport() {
+ let counter = 0;
+ const counterSetter = v => counter = v;
+ const module = wasmModuleWhichImportJS();
+ const instance = new WebAssembly.Instance(module, { imp: { func: counterSetter } });
+ for (let i = 0; i < 4096; ++i) {
+ // Invoke this a bunch of times to make sure the IC in the wasm -> JS stub works correctly.
+ instance.exports.changeCounter(i, 0);
+ assert.eq(counter, i + 42);
+ }
+})();
Modified: trunk/Source/_javascript_Core/ChangeLog (209667 => 209668)
--- trunk/Source/_javascript_Core/ChangeLog 2016-12-10 18:32:45 UTC (rev 209667)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-12-10 19:14:51 UTC (rev 209668)
@@ -1,3 +1,17 @@
+2016-12-10 Keith Miller <[email protected]>
+
+ Fix indirect_call if the result type is used.
+ https://bugs.webkit.org/show_bug.cgi?id=165727
+
+ Reviewed by Michael Saboff.
+
+ The patchpoint for indirect_call assumed that the callee would be
+ in params[0]. This is not the case, however, if the callee returns
+ a value.
+
+ * wasm/WasmB3IRGenerator.cpp:
+ (JSC::Wasm::B3IRGenerator::addCallIndirect):
+
2016-12-10 Konstantin Tokarev <[email protected]>
[cmake] Include WTF, JSC, and WebCore headers automatically to targers using them
Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp (209667 => 209668)
--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp 2016-12-10 18:32:45 UTC (rev 209667)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp 2016-12-10 19:14:51 UTC (rev 209668)
@@ -664,7 +664,8 @@
ExpressionType calleeCode = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), Origin(), callableFunction, OBJECT_OFFSETOF(CallableFunction, code));
- result = wasmCallingConvention().setupCall(m_proc, m_currentBlock, Origin(), args, toB3Type(signature->returnType),
+ Type returnType = signature->returnType;
+ result = wasmCallingConvention().setupCall(m_proc, m_currentBlock, Origin(), args, toB3Type(returnType),
[&] (PatchpointValue* patchpoint) {
patchpoint->effects.writesPinned = true;
patchpoint->effects.readsPinned = true;
@@ -672,7 +673,7 @@
patchpoint->append(calleeCode, ValueRep::SomeRegister);
patchpoint->setGenerator([=] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
- jit.call(params[0].gpr());
+ jit.call(params[returnType == Void ? 0 : 1].gpr());
});
});
return true;