wasm: fix producing programs with detached basic blocks

This commit is contained in:
Alexey Andreev 2023-09-22 20:26:05 +02:00
parent 98ec4597d6
commit 390861f835

View File

@ -62,6 +62,7 @@ import org.teavm.model.instructions.NullConstantInstruction;
import org.teavm.model.instructions.RaiseInstruction; import org.teavm.model.instructions.RaiseInstruction;
import org.teavm.model.instructions.SwitchInstruction; import org.teavm.model.instructions.SwitchInstruction;
import org.teavm.model.instructions.SwitchTableEntry; import org.teavm.model.instructions.SwitchTableEntry;
import org.teavm.model.optimization.UnreachableBasicBlockEliminator;
import org.teavm.model.util.DefinitionExtractor; import org.teavm.model.util.DefinitionExtractor;
import org.teavm.model.util.ProgramUtils; import org.teavm.model.util.ProgramUtils;
import org.teavm.runtime.ExceptionHandling; import org.teavm.runtime.ExceptionHandling;
@ -79,6 +80,7 @@ public class ExceptionHandlingShadowStackContributor {
private BasicBlock[] variableDefinitionPlaces; private BasicBlock[] variableDefinitionPlaces;
private boolean hasExceptionHandlers; private boolean hasExceptionHandlers;
private int parameterCount; private int parameterCount;
private boolean hasDetachedBlocks;
public int callSiteIdGen; public int callSiteIdGen;
@ -140,6 +142,10 @@ public class ExceptionHandlingShadowStackContributor {
} }
} }
if (hasDetachedBlocks) {
new UnreachableBasicBlockEliminator().optimize(program);
}
return hasExceptionHandlers; return hasExceptionHandlers;
} }
@ -218,6 +224,7 @@ public class ExceptionHandlingShadowStackContributor {
Instruction nextInsn = insn.getNext(); Instruction nextInsn = insn.getNext();
nextInsn.delete(); nextInsn.delete();
} }
hasDetachedBlocks = true;
last = true; last = true;
} else if (insn instanceof RaiseInstruction) { } else if (insn instanceof RaiseInstruction) {
InvokeInstruction raise = new InvokeInstruction(); InvokeInstruction raise = new InvokeInstruction();