From df8a3b820671fabfe9dc03c88597d92963195d9c Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 30 Mar 2015 18:14:48 +0400 Subject: [PATCH] Fix bug in liveness analyzer --- .../main/java/org/teavm/model/util/LivenessAnalyzer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/teavm-core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java b/teavm-core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java index cfb3ca677..665ff717d 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java +++ b/teavm-core/src/main/java/org/teavm/model/util/LivenessAnalyzer.java @@ -15,6 +15,8 @@ */ package org.teavm.model.util; +import com.carrotsearch.hppc.IntOpenHashSet; +import com.carrotsearch.hppc.IntSet; import java.util.ArrayDeque; import java.util.BitSet; import java.util.Deque; @@ -51,15 +53,19 @@ public class LivenessAnalyzer { BasicBlock block = program.basicBlockAt(i); for (Instruction insn : block.getInstructions()) { insn.acceptVisitor(usageExtractor); + IntSet usedVars = new IntOpenHashSet(); for (Variable var : usageExtractor.getUsedVariables()) { Task task = new Task(); task.block = i; task.var = var.getIndex(); stack.push(task); + usedVars.add(var.getIndex()); } insn.acceptVisitor(defExtractor); for (Variable var : defExtractor.getDefinedVariables()) { - definitions[var.getIndex()] = i; + if (!usedVars.contains(var.getIndex())) { + definitions[var.getIndex()] = i; + } } } for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {