Fixed: #2517 Loop break detection problems in some cases

This commit is contained in:
Jindra Petřík
2025-08-21 18:21:04 +02:00
parent 0024cb0897
commit c6889134d9
10 changed files with 152 additions and 25 deletions

View File

@@ -2656,6 +2656,7 @@ public class Graph {
currentLoop = null;
if (isLoop) {
currentLoop = new Loop(loops.size(), part, null);
currentLoop.stopParts = stopPart == null ? new ArrayList<>() : stopPart;
currentLoop.phase = 1;
loops.add(currentLoop);
}
@@ -2803,6 +2804,29 @@ public class Graph {
}
//When some of breakcandidates pass through current stoppart,
//Remove other candidantes.
if (!currentLoop.stopParts.isEmpty()) {
List<Integer> bcsLeft = new ArrayList<>();
for (int c = 0; c < currentLoop.breakCandidates.size(); c++) {
GraphPart cand = currentLoop.breakCandidates.get(c);
GraphPart sp = currentLoop.stopParts.get(currentLoop.stopParts.size() - 1);
if (cand == sp || cand.leadsTo(localData, this, code, sp, new ArrayList<>() /*ingore existing loop states*/, throwStates, false /* ?? */)) {
bcsLeft.add(c);
}
}
if (!bcsLeft.isEmpty()) {
for (int c = currentLoop.breakCandidates.size() - 1; c >= 0; c--) {
if (!bcsLeft.contains(c)) {
currentLoop.breakCandidates.remove(c);
currentLoop.breakCandidatesLevels.remove(c);
}
}
}
}
do {
found = null;