Skip to content

Commit fbb7747

Browse files
authored
Merge pull request github#2073 from hvitved/csharp/splitting-joins
Approved by calumgrant
2 parents 369c456 + 6ebefbb commit fbb7747

File tree

1 file changed

+30
-12
lines changed
  • csharp/ql/src/semmle/code/csharp/controlflow/internal

1 file changed

+30
-12
lines changed

csharp/ql/src/semmle/code/csharp/controlflow/internal/Splitting.qll

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,20 @@ module FinallySplitting {
527527
override string toString() { result = "Finally (" + nestLevel + ")" }
528528
}
529529

530+
pragma[noinline]
531+
private predicate hasEntry0(
532+
ControlFlowElement pred, FinallyControlFlowElement succ, int nestLevel, Completion c
533+
) {
534+
succ.isEntryNode() and
535+
nestLevel = nestLevel(succ.getTryStmt()) and
536+
succ = succ(pred, c)
537+
}
538+
530539
private class FinallySplitInternal extends SplitInternal, FinallySplitImpl {
531540
override FinallySplitKind getKind() { result.getNestLevel() = this.getNestLevel() }
532541

533542
override predicate hasEntry(ControlFlowElement pred, ControlFlowElement succ, Completion c) {
534-
succ = any(FinallyControlFlowElement entry |
535-
entry.isEntryNode() and
536-
this.getNestLevel() = nestLevel(entry.getTryStmt())
537-
) and
538-
succ = succ(pred, c) and
543+
hasEntry0(pred, succ, this.getNestLevel(), c) and
539544
this.getType().isSplitForEntryCompletion(c)
540545
}
541546

@@ -550,17 +555,22 @@ module FinallySplitting {
550555
(exists(succ(pred, _)) or exists(succExit(pred, _)))
551556
}
552557

558+
pragma[noinline]
559+
private predicate exit0(ControlFlowElement pred, TryStmt try, int nestLevel, Completion c) {
560+
this.appliesToPredecessor(pred) and
561+
nestLevel = nestLevel(try) and
562+
pred = last(try, c)
563+
}
564+
553565
/**
554566
* Holds if `pred` may exit this split with completion `c`. The Boolean
555567
* `inherited` indicates whether `c` is an inherited completion from a `try`/
556568
* `catch` block.
557569
*/
558570
private predicate exit(ControlFlowElement pred, Completion c, boolean inherited) {
559-
this.appliesToPredecessor(pred) and
560571
exists(TryStmt try, FinallySplitType type |
561-
type = this.getType() and
562-
nestLevel(try) = this.getNestLevel() and
563-
pred = last(try, c)
572+
exit0(pred, try, this.getNestLevel(), c) and
573+
type = this.getType()
564574
|
565575
if pred = last(try.getFinally(), c)
566576
then
@@ -1019,13 +1029,21 @@ module BooleanSplitting {
10191029
override string toString() { result = kind.toString() }
10201030
}
10211031

1032+
pragma[noinline]
1033+
private predicate hasEntry0(
1034+
ControlFlowElement pred, ControlFlowElement succ, BooleanSplitSubKind kind, boolean b,
1035+
Completion c
1036+
) {
1037+
kind.startsSplit(pred) and
1038+
succ = succ(pred, c) and
1039+
b = c.getInnerCompletion().(BooleanCompletion).getValue()
1040+
}
1041+
10221042
private class BooleanSplitInternal extends SplitInternal, BooleanSplitImpl {
10231043
override BooleanSplitKind getKind() { result.getSubKind() = this.getSubKind() }
10241044

10251045
override predicate hasEntry(ControlFlowElement pred, ControlFlowElement succ, Completion c) {
1026-
succ = succ(pred, c) and
1027-
this.getSubKind().startsSplit(pred) and
1028-
this.getBranch() = c.getInnerCompletion().(BooleanCompletion).getValue()
1046+
hasEntry0(pred, succ, this.getSubKind(), this.getBranch(), c)
10291047
}
10301048

10311049
override predicate hasEntry(Callable c, ControlFlowElement succ) { none() }

0 commit comments

Comments
 (0)