From 7459e5af01fbe3a8e75e73783794b4cdffda34e9 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Fri, 5 Feb 2016 05:11:50 -0800 Subject: Fix select The ordering changed in: https://github.com/WebAssembly/spec/pull/221 Which changed the spec tests, breaking sexpr-wasm because it pulls in the spec tests. This was then fixed: https://github.com/WebAssembly/sexpr-wasm-prototype/commit/23dc368148fc7827a603e3853f5a40287eb9effe Which in turn breaks when binaryen feeds sexpr-wasm .wast files with the old select operand ordering. Note that this PR has new failures when running the torture tests in binaryen-shell: the order of evaluation is correct in binaryen-shell but isn't emitted properly by LLVM in the .s files. This will require another patch to fix LLVM. --- src/asm2wasm.h | 2 +- src/s2wasm.h | 3 ++- src/wasm-interpreter.h | 6 +++--- src/wasm-s-parser.h | 6 +++--- src/wasm.h | 6 +++--- src/wasm2asm.h | 22 +++++++++++----------- 6 files changed, 23 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index d56bf0cce..22db2636a 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -1109,9 +1109,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { flip->right = get(); flip->type = i32; auto select = allocator.alloc(); auto inputs = getInputs(3); - curr->condition = inputs[0]; curr->ifTrue = inputs[1]; curr->ifFalse = inputs[2]; + curr->condition = inputs[0]; + assert(curr->condition->type == i32); curr->type = type; setOutput(curr, assign); }; diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 022dd04bc..3f9427ed7 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -620,13 +620,13 @@ private: } Flow visitSelect(Select *curr) { NOTE_ENTER("Select"); - Flow condition = visit(curr->condition); - if (condition.breaking()) return condition; - NOTE_EVAL1(condition.value); Flow ifTrue = visit(curr->ifTrue); if (ifTrue.breaking()) return ifTrue; Flow ifFalse = visit(curr->ifFalse); if (ifFalse.breaking()) return ifFalse; + Flow condition = visit(curr->condition); + if (condition.breaking()) return condition; + NOTE_EVAL1(condition.value); return condition.value.geti32() ? ifTrue : ifFalse; // ;-) } Flow visitReturn(Return *curr) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index e2a880e51..64dc6a454 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -633,9 +633,9 @@ private: Expression* makeSelect(Element& s, WasmType type) { auto ret = allocator.alloc