Fix "switch" with multiple "case" values for one block.

This commit is contained in:
Volker Berlin 2018-06-01 22:04:34 +02:00
parent dea54b631c
commit 9b3993450e
2 changed files with 8 additions and 3 deletions

View File

@ -283,13 +283,12 @@ class BranchManger {
// calculate the block number for ever switch case depending its position order
Arrays.sort( cases, ( a, b ) -> Integer.compare( a.position, b.position ) );
int blockCount = 0;
int blockCount = -1;
int lastPosition = -1;
BranchNode brTableNode = null;
BranchNode blockNode = null;
for( int i = 0; i < cases.length; i++ ) {
switchCase = cases[i];
switchCase.block = blockCount;
int currentPosition = switchCase.position;
if( lastPosition != currentPosition ) {
if( isTable && blockNode == null ) {
@ -303,6 +302,7 @@ class BranchManger {
}
blockNode = node;
}
switchCase.block = blockCount;
}
// handle the GOTO (breaks) at the end of the CASE blocks.

View File

@ -140,13 +140,18 @@ public class ControlFlowOperators extends AbstractBaseTest {
@Export
static int switchDirect() {
return tableSwitch(10) + (tableSwitch( 9 ) * 10) + (lookupSwitch(Integer.MAX_VALUE) * 100) + (lookupSwitch(0) * 1000);
return tableSwitch(10) + (tableSwitch( 9 ) * 10) + + (tableSwitch( -1 ) * 100) + (lookupSwitch(Integer.MAX_VALUE) * 1000) + (lookupSwitch(0) * 10000 );
}
private static int tableSwitch( int a ) {
int b;
switch(a){
case 8:
case 9:
b = 2;
break;
case 10:
case 11:
b = 1;
break;
default: