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

View File

@ -140,13 +140,18 @@ public class ControlFlowOperators extends AbstractBaseTest {
@Export @Export
static int switchDirect() { 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 ) { private static int tableSwitch( int a ) {
int b; int b;
switch(a){ switch(a){
case 8:
case 9:
b = 2;
break;
case 10: case 10:
case 11:
b = 1; b = 1;
break; break;
default: default: