Fix null checks on Address objects (Unmanaged annotation)

This commit is contained in:
lax1dude 2024-11-09 13:19:01 -08:00
parent 841e09cbd5
commit daf3a1c192
5 changed files with 30 additions and 5 deletions

View File

@ -74,6 +74,8 @@ import org.teavm.model.ListableClassHolderSource;
import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference;
import org.teavm.model.Program;
import org.teavm.model.lowlevel.Characteristics;
import org.teavm.model.lowlevel.LowLevelNullCheckFilter;
import org.teavm.model.transformation.BoundCheckInsertion;
import org.teavm.model.transformation.NullCheckFilter;
import org.teavm.model.transformation.NullCheckInsertion;
@ -86,7 +88,8 @@ import org.teavm.vm.spi.TeaVMHostExtension;
public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
private TeaVMTargetController controller;
private NullCheckInsertion nullCheckInsertion = new NullCheckInsertion(NullCheckFilter.EMPTY);
private Characteristics characteristics;
private NullCheckInsertion nullCheckInsertion;
private BoundCheckInsertion boundCheckInsertion = new BoundCheckInsertion();
private boolean strict;
private boolean obfuscated;
@ -179,6 +182,8 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
@Override
public void setController(TeaVMTargetController controller) {
this.controller = controller;
characteristics = new Characteristics(controller.getUnprocessedClassSource());
nullCheckInsertion = new NullCheckInsertion(new LowLevelNullCheckFilter(characteristics));
}
@Override
@ -267,6 +272,7 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
controller.getClassInitializerInfo(),
controller.getDependencyInfo(),
controller.getDiagnostics(),
characteristics,
customGenerators,
intrinsics,
customTypeMapperFactories,

View File

@ -44,6 +44,7 @@ import org.teavm.model.analysis.ClassInitializerInfo;
import org.teavm.model.analysis.ClassMetadataRequirements;
import org.teavm.model.classes.TagRegistry;
import org.teavm.model.classes.VirtualTableBuilder;
import org.teavm.model.lowlevel.Characteristics;
public class WasmGCDeclarationsGenerator {
public final ClassHierarchy hierarchy;
@ -61,6 +62,7 @@ public class WasmGCDeclarationsGenerator {
ClassInitializerInfo classInitializerInfo,
DependencyInfo dependencyInfo,
Diagnostics diagnostics,
Characteristics characteristics,
WasmGCCustomGeneratorProvider customGenerators,
WasmGCIntrinsicProvider intrinsics,
List<WasmGCCustomTypeMapperFactory> customTypeMapperFactories,
@ -83,6 +85,7 @@ public class WasmGCDeclarationsGenerator {
functionTypes,
names,
diagnostics,
characteristics,
customGenerators,
intrinsics,
strict,

View File

@ -43,6 +43,7 @@ import org.teavm.model.ClassReaderSource;
import org.teavm.model.ElementModifier;
import org.teavm.model.ListableClassReaderSource;
import org.teavm.model.MethodReference;
import org.teavm.model.lowlevel.Characteristics;
public class WasmGCGenerationContext implements BaseWasmGenerationContext {
private WasmModule module;
@ -69,6 +70,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
private String entryPoint;
private Consumer<WasmGCInitializerContributor> initializerContributors;
private Diagnostics diagnostics;
private Characteristics characteristics;
public WasmGCGenerationContext(WasmModule module, WasmGCVirtualTableProvider virtualTables,
WasmGCTypeMapper typeMapper, WasmFunctionTypes functionTypes, ListableClassReaderSource classes,
@ -78,7 +80,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
WasmGCCustomGeneratorProvider customGenerators, WasmGCIntrinsicProvider intrinsics,
WasmGCNameProvider names, boolean strict, String entryPoint,
Consumer<WasmGCInitializerContributor> initializerContributors,
Diagnostics diagnostics) {
Diagnostics diagnostics, Characteristics characteristics) {
this.module = module;
this.virtualTables = virtualTables;
this.typeMapper = typeMapper;
@ -98,6 +100,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
this.entryPoint = entryPoint;
this.initializerContributors = initializerContributors;
this.diagnostics = diagnostics;
this.characteristics = characteristics;
}
public WasmGCClassInfoProvider classInfoProvider() {
@ -210,6 +213,10 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
return diagnostics;
}
public Characteristics characteristics() {
return characteristics;
}
public Collection<String> getInterfaceImplementors(String className) {
if (interfaceImplementors == null) {
fillInterfaceImplementors();

View File

@ -15,6 +15,8 @@
*/
package org.teavm.backend.wasm.generate.gc.methods;
import static org.teavm.model.lowlevel.ExceptionHandlingUtil.isManagedMethodCall;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@ -97,6 +99,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
private WasmGCGenerationUtil generationUtil;
private WasmType expectedType;
private PreciseTypeInference types;
private boolean managed;
public WasmGCGenerationVisitor(WasmGCGenerationContext context, MethodReference currentMethod,
WasmFunction function, int firstVariable, boolean async, PreciseTypeInference types) {
@ -104,6 +107,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
this.context = context;
generationUtil = new WasmGCGenerationUtil(context.classInfoProvider());
this.types = types;
managed = context.characteristics().isManaged(currentMethod);
}
@Override
@ -125,7 +129,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
@Override
protected boolean isManaged() {
return true;
return managed;
}
@Override
@ -135,7 +139,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
@Override
protected boolean isManagedCall(MethodReference method) {
return false;
return isManagedMethodCall(context.characteristics(), method);
}
@Override

View File

@ -61,6 +61,7 @@ import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
import org.teavm.model.analysis.ClassInitializerInfo;
import org.teavm.model.lowlevel.Characteristics;
import org.teavm.model.util.RegisterAllocator;
public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
@ -74,6 +75,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
private WasmGCSupertypeFunctionProvider supertypeFunctions;
public final WasmGCNameProvider names;
private Diagnostics diagnostics;
private Characteristics characteristics;
private WasmGCTypeMapper typeMapper;
private WasmGCCustomGeneratorProvider customGenerators;
private WasmGCIntrinsicProvider intrinsics;
@ -101,6 +103,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
WasmFunctionTypes functionTypes,
WasmGCNameProvider names,
Diagnostics diagnostics,
Characteristics characteristics,
WasmGCCustomGeneratorProvider customGenerators,
WasmGCIntrinsicProvider intrinsics,
boolean strict,
@ -116,6 +119,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
this.functionTypes = functionTypes;
this.names = names;
this.diagnostics = diagnostics;
this.characteristics = characteristics;
this.customGenerators = customGenerators;
this.intrinsics = intrinsics;
this.strict = strict;
@ -367,7 +371,8 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
strict,
entryPoint,
initializerContributors,
diagnostics
diagnostics,
characteristics
);
}
return context;