Loops are followed by read(Unit) in order to prevent the CFA from thinking that the condition is returned

This commit is contained in:
Andrey Breslav
2011-04-14 19:53:32 +04:00
parent 9d32723cbf
commit 5963e952da
5 changed files with 69 additions and 12 deletions
@@ -332,6 +332,7 @@ public class JetControlFlowProcessor {
}
builder.jump(loopEntryPoint);
builder.exitLoop(expression);
builder.readUnit(expression);
}
@Override
@@ -348,6 +349,7 @@ public class JetControlFlowProcessor {
}
builder.jumpOnTrue(loopEntryPoint);
builder.exitLoop(expression);
builder.readUnit(expression);
}
@Override
@@ -363,6 +365,7 @@ public class JetControlFlowProcessor {
}
builder.nondeterministicJump(loopEntryPoint);
builder.exitLoop(expression);
builder.readUnit(expression);
}
@Override
@@ -366,7 +366,10 @@ public class TopDownAnalyzer {
collectReachable(enterInstruction, visited);
for (Instruction instruction : pseudocode.getInstructions()) {
if (!visited.contains(instruction) && instruction instanceof JetElementInstruction) {
if (!visited.contains(instruction) &&
instruction instanceof JetElementInstruction &&
// TODO : do {return} while (1 > a)
!(instruction instanceof ReadUnitValueInstruction)) {
unreachableElements.add(((JetElementInstruction) instruction).getElement());
}
}
@@ -376,13 +379,6 @@ public class TopDownAnalyzer {
public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection<JetElement> dominated) {
Instruction dominatorInstruction = representativeInstructions.get(dominator);
if (dominatorInstruction == null) {
// assert
// dominator instanceof JetContinueExpression ||
// dominator instanceof JetBreakExpression ||
// dominator instanceof JetReturnExpression ||
// dominator instanceof JetBlockExpression ||
// dominator instanceof JetFunctionLiteralExpression
// : "No representative instruction for a Nothing-typed expression: " + dominator.getText();
return;
}
SubroutineEnterInstruction enterInstruction = dominatorInstruction.getOwner().getEnterInstruction();
+10 -4
View File
@@ -227,8 +227,9 @@ l4:
l6:
r(2)
jmp(l3)
l1:
l2:
read (Unit)
l1:
<END>
=====================
== t3 ==
@@ -265,6 +266,7 @@ l5:
l6:
jmp(l4)
l3:
read (Unit)
r(5)
l2:
r(2)
@@ -303,8 +305,9 @@ l5:
read (Unit)
l6:
jmp(l4)
l2:
l3:
read (Unit)
l2:
r(2)
l1:
<END>
@@ -347,8 +350,9 @@ l4:
l6:
r(2)
jmp?(l3)
l1:
l2:
read (Unit)
l1:
<END>
=====================
== t3 ==
@@ -388,6 +392,7 @@ l5:
l6:
jmp?(l4)
l3:
read (Unit)
r(5)
l2:
r(2)
@@ -429,8 +434,9 @@ l5:
read (Unit)
l6:
jmp?(l4)
l2:
l3:
read (Unit)
l2:
r(2)
l1:
<END>
@@ -0,0 +1,42 @@
== main ==
fun main() {
while(1 > 0) {
2
}
}
---------------------
l0:
<START>
l3:
r(1)
r(0)
r(>)
r(1 > 0)
jf(l2)
r(2)
jmp(l3)
l2:
read (Unit)
l1:
<END>
=====================
== dowhile ==
fun dowhile() {
do {return}
while(1 > 0)
}
---------------------
l0:
<START>
l3:
ret l1
r(1)
r(0)
r(>)
r(1 > 0)
jt(l3)
l2:
read (Unit)
l1:
<END>
=====================
@@ -0,0 +1,10 @@
fun main() {
while(1 > 0) {
2
}
}
fun dowhile() {
do {return}
while(1 > 0)
}