Loops are followed by read(Unit) in order to prevent the CFA from thinking that the condition is returned
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user