From 13ec76dfbc1c72a5e77d6a33fca5bf349308162d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Nov 2017 17:08:28 -0800 Subject: Fix reading breaks to the function exit (#1304) * remove unneeded code to handle a br to the return from the function. Now that we use getBlockOrSingleton there, it does that for us anyhow --- src/wasm-binary.h | 1 - src/wasm/wasm-binary.cpp | 22 +++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 068f59d62..a407c56e4 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -864,7 +864,6 @@ public: }; std::vector breakStack; std::unordered_set breakTargetNames; - bool breaksToReturn; // whether a break is done to the function scope, which is in effect a return std::vector expressionStack; diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index b5bce8649..2d1e8734c 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1204,8 +1204,6 @@ void WasmBinaryWriter::visitDrop(Drop *curr) { // reader -static Name RETURN_BREAK("binaryen|break-to-return"); - void WasmBinaryBuilder::read() { readHeader(); @@ -1626,17 +1624,14 @@ void WasmBinaryBuilder::readFunctions() { if (debug) std::cerr << "processing function: " << i << std::endl; nextLabel = 0; useDebugLocation = false; - breaksToReturn = false; // process body assert(breakTargetNames.size() == 0); assert(breakStack.empty()); - breakStack.emplace_back(RETURN_BREAK, func->result != none); // the break target for the function scope assert(expressionStack.empty()); assert(depth == 0); func->body = getBlockOrSingleton(func->result); assert(depth == 0); - assert(breakStack.size() == 1); - breakStack.pop_back(); + assert(breakStack.size() == 0); assert(breakTargetNames.size() == 0); if (!expressionStack.empty()) { throw ParseException("stack not empty on function exit"); @@ -1644,10 +1639,6 @@ void WasmBinaryBuilder::readFunctions() { if (pos != endOfFunction) { throw ParseException("binary offset at function exit not at expected location"); } - if (breaksToReturn) { - // we broke to return, so we need an outer block to break to - func->body = Builder(wasm).blockifyWithName(func->body, RETURN_BREAK); - } } currFunction = nullptr; functions.push_back(func); @@ -2325,15 +2316,12 @@ void WasmBinaryBuilder::visitLoop(Loop *curr) { WasmBinaryBuilder::BreakTarget WasmBinaryBuilder::getBreakTarget(int32_t offset) { if (debug) std::cerr << "getBreakTarget " << offset << std::endl; + if (breakStack.size() < 1 + size_t(offset)) { + throw ParseException("bad breakindex (low)"); + } size_t index = breakStack.size() - 1 - offset; if (index >= breakStack.size()) { - throw ParseException("bad breakindex"); - } - if (index == 0) { - // trying to access the topmost element means we break out - // to the function scope, doing in effect a return, we'll - // need to create a block for that. - breaksToReturn = true; + throw ParseException("bad breakindex (high)"); } if (debug) std::cerr << "breaktarget "<< breakStack[index].name << " arity " << breakStack[index].arity << std::endl; auto& ret = breakStack[index]; -- cgit v1.2.3