Skip to content

Commit 81e1ab7

Browse files
authored
Merge pull request #21808 from aschackmull/cfg/switch-pattern-eval
Cfg: Rework CFG for switch case patterns.
2 parents 8cc6d78 + 048411e commit 81e1ab7

22 files changed

Lines changed: 2473 additions & 2000 deletions

File tree

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
8585

8686
predicate matchEdge(BasicBlock bb1, BasicBlock bb2) {
8787
bb1.getASuccessor(any(MatchingSuccessor s | s.getValue() = true)) = bb2 and
88-
bb1.getLastNode() = AstNode.super.getControlFlowNode()
88+
bb1.getLastNode() = super.getPattern().getControlFlowNode()
8989
}
9090

9191
predicate nonMatchEdge(BasicBlock bb1, BasicBlock bb2) {
9292
bb1.getASuccessor(any(MatchingSuccessor s | s.getValue() = false)) = bb2 and
93-
bb1.getLastNode() = AstNode.super.getControlFlowNode()
93+
bb1.getLastNode() = super.getPattern().getControlFlowNode()
9494
}
9595
}
9696

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ module Ast implements AstSig<Location> {
229229
final private class FinalCase = CS::Case;
230230

231231
class Case extends FinalCase {
232-
AstNode getAPattern() { result = this.getPattern() }
232+
AstNode getPattern(int index) { result = this.getPattern() and index = 0 }
233233

234234
Expr getGuard() { result = this.getCondition() }
235235

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

Lines changed: 126 additions & 123 deletions
Large diffs are not rendered by default.

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

Lines changed: 256 additions & 251 deletions
Large diffs are not rendered by default.

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

Lines changed: 1159 additions & 957 deletions
Large diffs are not rendered by default.

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

Lines changed: 200 additions & 99 deletions
Large diffs are not rendered by default.

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

Lines changed: 310 additions & 212 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/controlflow/guards/BooleanGuardedExpr.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false |
8080
| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false |
8181
| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | false |
82-
| Guards.cs:334:13:334:15 | access to constant B | Guards.cs:334:13:334:20 | ... => ... | Guards.cs:334:13:334:15 | access to constant B | true |
8382
| Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | false |
8483
| Guards.cs:343:31:343:31 | access to local variable s | Guards.cs:342:13:342:21 | ... != ... | Guards.cs:342:13:342:13 | access to local variable s | true |
8584
| Guards.cs:349:13:349:13 | access to parameter o | Guards.cs:348:13:348:25 | ... is ... | Guards.cs:348:13:348:13 | access to parameter o | true |

csharp/ql/test/library-tests/controlflow/guards/GuardedControlFlowNode.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@
202202
| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false |
203203
| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | false |
204204
| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:28 | call to method ToString | false |
205-
| Guards.cs:334:13:334:15 | access to constant B | Guards.cs:334:13:334:20 | ... => ... | Guards.cs:334:13:334:15 | access to constant B | true |
206205
| Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | false |
207206
| Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:32 | ... ? ... : ... | Guards.cs:341:20:341:20 | access to parameter b | not null |
208207
| Guards.cs:343:31:343:31 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | not null |

csharp/ql/test/library-tests/controlflow/guards/GuardedExpr.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@
202202
| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false |
203203
| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | false |
204204
| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:28 | call to method ToString | false |
205-
| Guards.cs:334:13:334:15 | access to constant B | Guards.cs:334:13:334:20 | ... => ... | Guards.cs:334:13:334:15 | access to constant B | true |
206205
| Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | false |
207206
| Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:32 | ... ? ... : ... | Guards.cs:341:20:341:20 | access to parameter b | not null |
208207
| Guards.cs:343:31:343:31 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | not null |

0 commit comments

Comments
 (0)