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.jump(loopEntryPoint);
|
||||||
builder.exitLoop(expression);
|
builder.exitLoop(expression);
|
||||||
|
builder.readUnit(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -348,6 +349,7 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
builder.jumpOnTrue(loopEntryPoint);
|
builder.jumpOnTrue(loopEntryPoint);
|
||||||
builder.exitLoop(expression);
|
builder.exitLoop(expression);
|
||||||
|
builder.readUnit(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -363,6 +365,7 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
builder.nondeterministicJump(loopEntryPoint);
|
builder.nondeterministicJump(loopEntryPoint);
|
||||||
builder.exitLoop(expression);
|
builder.exitLoop(expression);
|
||||||
|
builder.readUnit(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -366,7 +366,10 @@ public class TopDownAnalyzer {
|
|||||||
collectReachable(enterInstruction, visited);
|
collectReachable(enterInstruction, visited);
|
||||||
|
|
||||||
for (Instruction instruction : pseudocode.getInstructions()) {
|
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());
|
unreachableElements.add(((JetElementInstruction) instruction).getElement());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,13 +379,6 @@ public class TopDownAnalyzer {
|
|||||||
public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection<JetElement> dominated) {
|
public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection<JetElement> dominated) {
|
||||||
Instruction dominatorInstruction = representativeInstructions.get(dominator);
|
Instruction dominatorInstruction = representativeInstructions.get(dominator);
|
||||||
if (dominatorInstruction == null) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
SubroutineEnterInstruction enterInstruction = dominatorInstruction.getOwner().getEnterInstruction();
|
SubroutineEnterInstruction enterInstruction = dominatorInstruction.getOwner().getEnterInstruction();
|
||||||
|
|||||||
@@ -227,8 +227,9 @@ l4:
|
|||||||
l6:
|
l6:
|
||||||
r(2)
|
r(2)
|
||||||
jmp(l3)
|
jmp(l3)
|
||||||
l1:
|
|
||||||
l2:
|
l2:
|
||||||
|
read (Unit)
|
||||||
|
l1:
|
||||||
<END>
|
<END>
|
||||||
=====================
|
=====================
|
||||||
== t3 ==
|
== t3 ==
|
||||||
@@ -265,6 +266,7 @@ l5:
|
|||||||
l6:
|
l6:
|
||||||
jmp(l4)
|
jmp(l4)
|
||||||
l3:
|
l3:
|
||||||
|
read (Unit)
|
||||||
r(5)
|
r(5)
|
||||||
l2:
|
l2:
|
||||||
r(2)
|
r(2)
|
||||||
@@ -303,8 +305,9 @@ l5:
|
|||||||
read (Unit)
|
read (Unit)
|
||||||
l6:
|
l6:
|
||||||
jmp(l4)
|
jmp(l4)
|
||||||
l2:
|
|
||||||
l3:
|
l3:
|
||||||
|
read (Unit)
|
||||||
|
l2:
|
||||||
r(2)
|
r(2)
|
||||||
l1:
|
l1:
|
||||||
<END>
|
<END>
|
||||||
@@ -347,8 +350,9 @@ l4:
|
|||||||
l6:
|
l6:
|
||||||
r(2)
|
r(2)
|
||||||
jmp?(l3)
|
jmp?(l3)
|
||||||
l1:
|
|
||||||
l2:
|
l2:
|
||||||
|
read (Unit)
|
||||||
|
l1:
|
||||||
<END>
|
<END>
|
||||||
=====================
|
=====================
|
||||||
== t3 ==
|
== t3 ==
|
||||||
@@ -388,6 +392,7 @@ l5:
|
|||||||
l6:
|
l6:
|
||||||
jmp?(l4)
|
jmp?(l4)
|
||||||
l3:
|
l3:
|
||||||
|
read (Unit)
|
||||||
r(5)
|
r(5)
|
||||||
l2:
|
l2:
|
||||||
r(2)
|
r(2)
|
||||||
@@ -429,8 +434,9 @@ l5:
|
|||||||
read (Unit)
|
read (Unit)
|
||||||
l6:
|
l6:
|
||||||
jmp?(l4)
|
jmp?(l4)
|
||||||
l2:
|
|
||||||
l3:
|
l3:
|
||||||
|
read (Unit)
|
||||||
|
l2:
|
||||||
r(2)
|
r(2)
|
||||||
l1:
|
l1:
|
||||||
<END>
|
<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