use "java/lang/Object" as fallback type for NULL values

This commit is contained in:
Volker Berlin 2022-05-08 18:53:45 +02:00
parent 23199840c8
commit 52dd9a1665
No known key found for this signature in database
GPG Key ID: 988423EF815BE4CB

View File

@ -967,23 +967,30 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
int size = instructions.size(); int size = instructions.size();
for( int i = 0; i < size; i++ ) { for( int i = 0; i < size; i++ ) {
WasmInstruction instr = instructions.get( i ); WasmInstruction instr = instructions.get( i );
if( instr.getType() == Type.Struct ) { try {
WasmStructInstruction structInst = (WasmStructInstruction)instr; if( instr.getType() == Type.Struct ) {
if( structInst.getOperator() == StructOperator.NULL ) { WasmStructInstruction structInst = (WasmStructInstruction)instr;
int count = 0; if( structInst.getOperator() == StructOperator.NULL ) {
for( int s = i + 1; s < size; s++ ) { int count = 0;
WasmInstruction nextInstr = instructions.get( s ); for( int s = i + 1; s < size; s++ ) {
count -= nextInstr.getPopCount(); WasmInstruction nextInstr = instructions.get( s );
if( count < 0 ) { count -= nextInstr.getPopCount();
AnyType[] popValueTypes = nextInstr.getPopValueTypes(); if( count < 0 ) {
structInst.setStructType( (StructType)popValueTypes[-1 - count] ); AnyType[] popValueTypes = nextInstr.getPopValueTypes();
break; AnyType type = popValueTypes[-1 - count];
} // is the fallback to java/lang/Object right? There can also be a NULL value for external.
if( nextInstr.getPushValueType() != null ) { StructType structType = type instanceof StructType ? (StructType)type : getTypeManager().valueOf( "java/lang/Object" );
count++; structInst.setStructType( structType );
break;
}
if( nextInstr.getPushValueType() != null ) {
count++;
}
} }
} }
} }
} catch( Exception ex ) {
throw WasmException.create( ex, instr.getLineNumber() );
} }
} }
} }