@@ -1204,8 +1204,6 @@ void WasmBinaryWriter::visitDrop(Drop *curr) {
12041204
12051205// reader
12061206
1207- static Name RETURN_BREAK (" binaryen|break-to-return" );
1208-
12091207void WasmBinaryBuilder::read () {
12101208
12111209 readHeader ();
@@ -1626,28 +1624,21 @@ void WasmBinaryBuilder::readFunctions() {
16261624 if (debug) std::cerr << " processing function: " << i << std::endl;
16271625 nextLabel = 0 ;
16281626 useDebugLocation = false ;
1629- breaksToReturn = false ;
16301627 // process body
16311628 assert (breakTargetNames.size () == 0 );
16321629 assert (breakStack.empty ());
1633- breakStack.emplace_back (RETURN_BREAK, func->result != none); // the break target for the function scope
16341630 assert (expressionStack.empty ());
16351631 assert (depth == 0 );
16361632 func->body = getBlockOrSingleton (func->result );
16371633 assert (depth == 0 );
1638- assert (breakStack.size () == 1 );
1639- breakStack.pop_back ();
1634+ assert (breakStack.size () == 0 );
16401635 assert (breakTargetNames.size () == 0 );
16411636 if (!expressionStack.empty ()) {
16421637 throw ParseException (" stack not empty on function exit" );
16431638 }
16441639 if (pos != endOfFunction) {
16451640 throw ParseException (" binary offset at function exit not at expected location" );
16461641 }
1647- if (breaksToReturn) {
1648- // we broke to return, so we need an outer block to break to
1649- func->body = Builder (wasm).blockifyWithName (func->body , RETURN_BREAK);
1650- }
16511642 }
16521643 currFunction = nullptr ;
16531644 functions.push_back (func);
@@ -2325,15 +2316,12 @@ void WasmBinaryBuilder::visitLoop(Loop *curr) {
23252316
23262317WasmBinaryBuilder::BreakTarget WasmBinaryBuilder::getBreakTarget (int32_t offset) {
23272318 if (debug) std::cerr << " getBreakTarget " << offset << std::endl;
2319+ if (breakStack.size () < 1 + size_t (offset)) {
2320+ throw ParseException (" bad breakindex (low)" );
2321+ }
23282322 size_t index = breakStack.size () - 1 - offset;
23292323 if (index >= breakStack.size ()) {
2330- throw ParseException (" bad breakindex" );
2331- }
2332- if (index == 0 ) {
2333- // trying to access the topmost element means we break out
2334- // to the function scope, doing in effect a return, we'll
2335- // need to create a block for that.
2336- breaksToReturn = true ;
2324+ throw ParseException (" bad breakindex (high)" );
23372325 }
23382326 if (debug) std::cerr << " breaktarget " << breakStack[index].name << " arity " << breakStack[index].arity << std::endl;
23392327 auto & ret = breakStack[index];
0 commit comments