Skip to content

Commit fdc8abc

Browse files
committed
C#: Fix CFG by removing unnecessary edge.
1 parent d696235 commit fdc8abc

File tree

6 files changed

+8
-14
lines changed

6 files changed

+8
-14
lines changed

csharp/ql/src/semmle/code/csharp/controlflow/ControlFlowGraph.qll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,6 @@ module ControlFlow {
947947
result = cs.getCondition() and
948948
c = specificBoolean(false)
949949
)
950-
or
951-
// Last statement exits with any non-break completion
952-
exists(int last | last = max(int i | exists(ss.getStmt(i))) |
953-
result = ss.getStmt(last) and
954-
c = TRec(TLastRecNonBreakCompletion())
955-
)
956950
)
957951
or
958952
cfe = any(SwitchExpr se |

csharp/ql/test/library-tests/controlflow/graph/Consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ breakInvariant2
44
breakInvariant3
55
breakInvariant4
66
breakInvariant5
7+
multipleSuccessors

csharp/ql/test/library-tests/controlflow/graph/Consistency.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,10 @@ query predicate breakInvariant5(
9494
not (split.hasSuccessor(pred, succ, c) and split = predSplits.getASplit()) and
9595
not (split.hasEntry(pred, succ, c) and not split = predSplits.getASplit())
9696
}
97+
98+
query predicate multipleSuccessors(
99+
ControlFlow::Node node, SuccessorType t, ControlFlow::Node successor
100+
) {
101+
strictcount(node.getASuccessorByType(t)) > 1 and
102+
successor = node.getASuccessorByType(t)
103+
}

csharp/ql/test/library-tests/controlflow/graph/Dominance.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,7 +5124,6 @@ postDominance
51245124
| Switch.cs:131:48:131:51 | null | Switch.cs:131:43:131:43 | _ |
51255125
| Switch.cs:134:9:134:11 | exit M13 | Switch.cs:138:22:138:31 | return ...; |
51265126
| Switch.cs:134:9:134:11 | exit M13 | Switch.cs:139:21:139:29 | return ...; |
5127-
| Switch.cs:134:9:134:11 | exit M13 | Switch.cs:140:18:140:18 | 2 |
51285127
| Switch.cs:134:9:134:11 | exit M13 | Switch.cs:140:21:140:29 | return ...; |
51295128
| Switch.cs:135:5:142:5 | {...} | Switch.cs:134:9:134:11 | enter M13 |
51305129
| Switch.cs:136:9:141:9 | switch (...) {...} | Switch.cs:135:5:142:5 | {...} |
@@ -5139,7 +5138,6 @@ postDominance
51395138
| Switch.cs:140:21:140:29 | return ...; | Switch.cs:140:28:140:28 | 2 |
51405139
| Switch.cs:144:9:144:11 | exit M14 | Switch.cs:148:21:148:29 | return ...; |
51415140
| Switch.cs:144:9:144:11 | exit M14 | Switch.cs:149:22:149:31 | return ...; |
5142-
| Switch.cs:144:9:144:11 | exit M14 | Switch.cs:150:18:150:18 | 2 |
51435141
| Switch.cs:144:9:144:11 | exit M14 | Switch.cs:150:21:150:29 | return ...; |
51445142
| Switch.cs:145:5:152:5 | {...} | Switch.cs:144:9:144:11 | enter M14 |
51455143
| Switch.cs:146:9:151:9 | switch (...) {...} | Switch.cs:145:5:152:5 | {...} |

csharp/ql/test/library-tests/controlflow/graph/ExitElement.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,11 +2435,9 @@
24352435
| Switch.cs:131:56:131:66 | call to method ToString | Switch.cs:131:56:131:66 | call to method ToString | normal |
24362436
| Switch.cs:135:5:142:5 | {...} | Switch.cs:138:22:138:31 | return ...; | return |
24372437
| Switch.cs:135:5:142:5 | {...} | Switch.cs:139:21:139:29 | return ...; | return |
2438-
| Switch.cs:135:5:142:5 | {...} | Switch.cs:140:18:140:18 | 2 | no-match |
24392438
| Switch.cs:135:5:142:5 | {...} | Switch.cs:140:21:140:29 | return ...; | return |
24402439
| Switch.cs:136:9:141:9 | switch (...) {...} | Switch.cs:138:22:138:31 | return ...; | return |
24412440
| Switch.cs:136:9:141:9 | switch (...) {...} | Switch.cs:139:21:139:29 | return ...; | return |
2442-
| Switch.cs:136:9:141:9 | switch (...) {...} | Switch.cs:140:18:140:18 | 2 | no-match |
24432441
| Switch.cs:136:9:141:9 | switch (...) {...} | Switch.cs:140:21:140:29 | return ...; | return |
24442442
| Switch.cs:136:17:136:17 | access to parameter i | Switch.cs:136:17:136:17 | access to parameter i | normal |
24452443
| Switch.cs:138:13:138:20 | default: | Switch.cs:138:22:138:31 | return ...; | return |
@@ -2460,11 +2458,9 @@
24602458
| Switch.cs:140:28:140:28 | 2 | Switch.cs:140:28:140:28 | 2 | normal |
24612459
| Switch.cs:145:5:152:5 | {...} | Switch.cs:148:21:148:29 | return ...; | return |
24622460
| Switch.cs:145:5:152:5 | {...} | Switch.cs:149:22:149:31 | return ...; | return |
2463-
| Switch.cs:145:5:152:5 | {...} | Switch.cs:150:18:150:18 | 2 | no-match |
24642461
| Switch.cs:145:5:152:5 | {...} | Switch.cs:150:21:150:29 | return ...; | return |
24652462
| Switch.cs:146:9:151:9 | switch (...) {...} | Switch.cs:148:21:148:29 | return ...; | return |
24662463
| Switch.cs:146:9:151:9 | switch (...) {...} | Switch.cs:149:22:149:31 | return ...; | return |
2467-
| Switch.cs:146:9:151:9 | switch (...) {...} | Switch.cs:150:18:150:18 | 2 | no-match |
24682464
| Switch.cs:146:9:151:9 | switch (...) {...} | Switch.cs:150:21:150:29 | return ...; | return |
24692465
| Switch.cs:146:17:146:17 | access to parameter i | Switch.cs:146:17:146:17 | access to parameter i | normal |
24702466
| Switch.cs:148:13:148:19 | case ...: | Switch.cs:148:18:148:18 | 1 | no-match |

csharp/ql/test/library-tests/controlflow/graph/NodeGraph.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,6 @@
25502550
| Switch.cs:139:21:139:29 | return ...; | Switch.cs:134:9:134:11 | exit M13 | semmle.label | return |
25512551
| Switch.cs:139:28:139:28 | 1 | Switch.cs:139:21:139:29 | return ...; | semmle.label | successor |
25522552
| Switch.cs:140:13:140:19 | case ...: | Switch.cs:140:18:140:18 | 2 | semmle.label | successor |
2553-
| Switch.cs:140:18:140:18 | 2 | Switch.cs:134:9:134:11 | exit M13 | semmle.label | no-match |
25542553
| Switch.cs:140:18:140:18 | 2 | Switch.cs:138:13:138:20 | default: | semmle.label | no-match |
25552554
| Switch.cs:140:18:140:18 | 2 | Switch.cs:140:28:140:28 | 2 | semmle.label | match |
25562555
| Switch.cs:140:21:140:29 | return ...; | Switch.cs:134:9:134:11 | exit M13 | semmle.label | return |
@@ -2569,7 +2568,6 @@
25692568
| Switch.cs:149:29:149:30 | -... | Switch.cs:149:22:149:31 | return ...; | semmle.label | successor |
25702569
| Switch.cs:149:30:149:30 | 1 | Switch.cs:149:29:149:30 | -... | semmle.label | successor |
25712570
| Switch.cs:150:13:150:19 | case ...: | Switch.cs:150:18:150:18 | 2 | semmle.label | successor |
2572-
| Switch.cs:150:18:150:18 | 2 | Switch.cs:144:9:144:11 | exit M14 | semmle.label | no-match |
25732571
| Switch.cs:150:18:150:18 | 2 | Switch.cs:149:13:149:20 | default: | semmle.label | no-match |
25742572
| Switch.cs:150:18:150:18 | 2 | Switch.cs:150:28:150:28 | 2 | semmle.label | match |
25752573
| Switch.cs:150:21:150:29 | return ...; | Switch.cs:144:9:144:11 | exit M14 | semmle.label | return |

0 commit comments

Comments
 (0)