Fix an issue with instance-of type inference

We should only infer the register type after an if-eqz/nez if it has a
single predecessor that is the instance-of instruction.
This commit is contained in:
Ben Gruver 2016-09-11 11:14:27 -07:00
parent 9ec379a561
commit 26a4f1e603
2 changed files with 6 additions and 2 deletions

View File

@ -368,7 +368,8 @@ public class AnalyzedInstruction implements Comparable<AnalyzedInstruction> {
return false;
}
if (instruction.getOpcode() == Opcode.IF_EQZ || instruction.getOpcode() == Opcode.IF_NEZ) {
if (getPredecessorCount() == 1 && (instruction.getOpcode() == Opcode.IF_EQZ ||
instruction.getOpcode() == Opcode.IF_NEZ)) {
AnalyzedInstruction previousInstruction = getPreviousInstruction();
if (previousInstruction != null &&
previousInstruction.instruction.getOpcode() == Opcode.INSTANCE_OF &&

View File

@ -1206,7 +1206,10 @@ public class MethodAnalyzer {
private void analyzeIfEqzNez(@Nonnull AnalyzedInstruction analyzedInstruction) {
int instructionIndex = analyzedInstruction.getInstructionIndex();
if (instructionIndex > 0) {
AnalyzedInstruction prevAnalyzedInstruction = analyzedInstructions.valueAt(instructionIndex - 1);
if (analyzedInstruction.getPredecessorCount() != 1) {
return;
}
AnalyzedInstruction prevAnalyzedInstruction = analyzedInstruction.getPredecessors().first();
if (prevAnalyzedInstruction.instruction.getOpcode() == Opcode.INSTANCE_OF) {
if (canNarrowAfterInstanceOf(prevAnalyzedInstruction, analyzedInstruction, classPath)) {
List<Integer> narrowingRegisters = Lists.newArrayList();