END can not be outside of parent block

This commit is contained in:
Volker 2018-08-10 20:35:17 +02:00
parent b5296e6268
commit 0822d9af8c
2 changed files with 7 additions and 4 deletions

View File

@ -260,10 +260,13 @@ class BranchManger {
if( i > 0 ) {
calculate( branch, parsedOperations.subList( 0, i ) );
}
branch.data = calculateBlockType( startPos, branch.endPos );
endPos = parsedBlock.endPosition;
ValueType blockType = calculateBlockType( startPos, branch.endPos );
branch.data = blockType;
// end position can not be outside of the parent
endPos = Math.min( parsedBlock.endPosition, parent.endPos );
int breakDeep = calculateBreakDeep( parent, endPos );
// if with block type signature must have an else block
int breakDeep = blockType == ValueType.empty ? calculateBreakDeep( parent, endPos ) : -1;
if( breakDeep >= 0 ) {
branch.endOp = WasmBlockOperator.END;
branch.add( new BranchNode( startBlock.endPosition, endPos, WasmBlockOperator.BR, null, breakDeep + 1 ) );

View File

@ -299,7 +299,7 @@ public class ControlFlowOperators extends AbstractBaseTest {
@Export
static int conditionalOperator () {
int condition = 4;
return condition >= 4 ? 1 : 2;
return condition >= 4 ? condition < 4 ? 1 : 2 : condition == 4 ? 3 : 4;
}
}
}