mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
fix reuse of local variable slot for empty catch blocks
This commit is contained in:
parent
5ec2e34c57
commit
06fc9dddfd
@ -240,22 +240,29 @@ class LocaleVariableManager {
|
|||||||
*/
|
*/
|
||||||
void use( AnyType valueType, int slot, int javaCodePos ) {
|
void use( AnyType valueType, int slot, int javaCodePos ) {
|
||||||
int idx = get( slot, javaCodePos );
|
int idx = get( slot, javaCodePos );
|
||||||
useImpl( valueType, idx );
|
useImpl( valueType, idx, javaCodePos );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void useImpl( AnyType valueType, int idx ) {
|
private void useImpl( AnyType valueType, int idx, int javaCodePos ) {
|
||||||
Variable var = variables[idx];
|
Variable var = variables[idx];
|
||||||
if( var.valueType != null && var.valueType != valueType ) {
|
if( var.valueType != null && var.valueType != valueType ) {
|
||||||
if( var.valueType.getCode() >= 0 && valueType == ValueType.anyref ) {
|
if( var.valueType.isSubTypeOf( valueType ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( valueType.getCode() >= 0 && var.valueType == ValueType.anyref ) {
|
if( valueType.isSubTypeOf( var.valueType ) ) {
|
||||||
// set the more specific type
|
// set the more specific type
|
||||||
|
} else if( var.endPos == Integer.MAX_VALUE && javaCodePos > 0 ) {
|
||||||
|
// seems the slot was reused with a different type, in WASM we need to use 2 variables in this case
|
||||||
|
var.endPos = javaCodePos - 1;
|
||||||
|
idx = size;
|
||||||
|
resetAddVar( valueType, var.idx );
|
||||||
|
var = variables[idx];
|
||||||
|
var.startPos = javaCodePos;
|
||||||
|
} else if( types.isFinish() ) {
|
||||||
|
throw new WasmException( "Redefine local variable '" + var.name + "' type from " + var.valueType + " to " + valueType + " in slot " + var.idx
|
||||||
|
+ ". Compile the Java code with debug information to correct this problem.", null, null, -1 );
|
||||||
} else {
|
} else {
|
||||||
return;// TODO we need a better check
|
return; // in the scan phase not all types are known
|
||||||
// throw new WasmException( "Redefine local variable '" + var.name + "' type from " + var.valueType + " to " + valueType + " in slot "
|
|
||||||
// + slot + ". Compile the Java code with debug information to correct this problem.", null, null, -1 );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var.valueType = valueType;
|
var.valueType = valueType;
|
||||||
@ -265,7 +272,7 @@ return;// TODO we need a better check
|
|||||||
while( size <= wasmIdx ) {
|
while( size <= wasmIdx ) {
|
||||||
resetAddVar( null, size );
|
resetAddVar( null, size );
|
||||||
}
|
}
|
||||||
useImpl( valueType, wasmIdx );
|
useImpl( valueType, wasmIdx, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,6 +117,15 @@ public class TypeManager {
|
|||||||
return structTypes.size();
|
return structTypes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the scan phase is finish
|
||||||
|
*
|
||||||
|
* @return true, if scan phase is finish
|
||||||
|
*/
|
||||||
|
boolean isFinish() {
|
||||||
|
return isFinish;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan the hierarchy of the types.
|
* Scan the hierarchy of the types.
|
||||||
*
|
*
|
||||||
@ -497,6 +506,14 @@ public class TypeManager {
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isSubTypeOf( AnyType type ) {
|
||||||
|
return type == this || type == ValueType.anyref;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the Java type
|
* Get the name of the Java type
|
||||||
* @return the name
|
* @return the name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user