diff --git a/teavm-core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java b/teavm-core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java index 9c705b390..febae389c 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java +++ b/teavm-core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java @@ -21,6 +21,7 @@ import org.teavm.dependency.DependencyInfo; import org.teavm.diagnostics.Diagnostics; import org.teavm.model.*; import org.teavm.model.instructions.*; +import org.teavm.optimization.UnreachableBasicBlockEliminator; /** * @@ -61,6 +62,7 @@ public class MissingItemsProcessor { } } } + new UnreachableBasicBlockEliminator().optimize(program); } private void truncateBlock(BasicBlock block, int index) { diff --git a/teavm-core/src/main/java/org/teavm/optimization/UnreachableBasicBlockEliminator.java b/teavm-core/src/main/java/org/teavm/optimization/UnreachableBasicBlockEliminator.java index d859df66e..d0930fafb 100644 --- a/teavm-core/src/main/java/org/teavm/optimization/UnreachableBasicBlockEliminator.java +++ b/teavm-core/src/main/java/org/teavm/optimization/UnreachableBasicBlockEliminator.java @@ -53,6 +53,16 @@ public class UnreachableBasicBlockEliminator { } for (int i = 0; i < reachable.length; ++i) { if (!reachable[i]) { + BasicBlock block = program.basicBlockAt(i); + if (block.getLastInstruction() != null) { + block.getLastInstruction().acceptVisitor(transitionExtractor); + for (BasicBlock successor : transitionExtractor.getTargets()) { + successor.removeIncomingsFrom(block); + } + } + for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { + tryCatch.getHandler().removeIncomingsFrom(block); + } program.deleteBasicBlock(i); } } diff --git a/teavm-core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java b/teavm-core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java index 872d4584d..939f2601c 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java +++ b/teavm-core/src/main/java/org/teavm/parsing/ClassRefsRenamer.java @@ -22,12 +22,13 @@ import org.teavm.javascript.ni.Rename; import org.teavm.javascript.ni.Superclass; import org.teavm.model.*; import org.teavm.model.instructions.*; +import org.teavm.model.util.ModelUtils; /** * * @author Alexey Andreev */ -class ClassRefsRenamer implements InstructionVisitor { +public class ClassRefsRenamer implements InstructionVisitor { private Mapper classNameMapper; public ClassRefsRenamer(Mapper classNameMapper) { @@ -54,8 +55,7 @@ class ClassRefsRenamer implements InstructionVisitor { renamedCls.addMethod(rename(method)); } for (FieldHolder field : cls.getFields().toArray(new FieldHolder[0])) { - cls.removeField(field); - renamedCls.addField(field); + renamedCls.addField(ModelUtils.copyField(field)); } if (cls.getOwnerName() != null) { renamedCls.setOwnerName(classNameMapper.map(cls.getOwnerName()));