Skip to content

Commit b781737

Browse files
committed
Unified: Support capture declarations in the CFG.
1 parent acd0872 commit b781737

4 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private module Ast implements AstSig<Location> {
4040
not n instanceof Callable and
4141
not skipControlFlow(n) and
4242
not skipControlFlow(result)
43+
or
44+
n.(FunctionExpr).getCaptureDeclaration(index) = result
4345
}
4446

4547
Callable getEnclosingCallable(AstNode node) { result = node.getEnclosingCallable() }

‎unified/ql/test/library-tests/controlflow/basicblock-slices.expected‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311
| 380 | cfg.swift:380:1:384:1 | FunctionDeclaration | 'FunctionDeclaration' |
312312
| 380 | cfg.swift:380:18:380:18 | x | 'x -> y -^ Block' |
313313
| 381 | cfg.swift:381:10:383:3 | Block | 'Block' |
314-
| 381 | cfg.swift:381:10:383:3 | FunctionExpr | 'FunctionExpr -^ ReturnExpr' |
314+
| 381 | cfg.swift:381:13:381:22 | VariableDeclaration | 'VariableDeclaration -V z -> x -> y -^ BinaryExpr -> VariableDeclaration -V t -> "literal" -^ FunctionExpr -^ ReturnExpr' |
315315
| 382 | cfg.swift:382:12:382:12 | z | 'z -^ ReturnExpr' |
316316
| 386 | cfg.swift:386:1:388:1 | FunctionDeclaration | 'FunctionDeclaration' |
317317
| 386 | cfg.swift:386:23:386:23 | t | 't -^ Block' |

‎unified/ql/test/library-tests/controlflow/cfg.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ noCfg
149149
| cfg.swift:358:6:358:28 | loop_with_identity_expr |
150150
| cfg.swift:371:8:371:18 | getOptional |
151151
| cfg.swift:380:45:380:47 | Int |
152-
| cfg.swift:381:13:381:13 | z |
153152
| cfg.swift:421:6:421:22 | localDeclarations |
154153
| cfg.swift:468:6:468:17 | testIfConfig |
155154
| cfg.swift:497:6:497:18 | testAvailable |

‎unified/ql/test/library-tests/controlflow/cfg.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func testOptional(c : OptionalC?) -> Int? {
378378
}
379379

380380
func testCapture(x : Int, y : Int) -> () -> Int { // $ noCfg
381-
return { [z = x + y, t = "literal"] in // $ noCfg
381+
return { [z = x + y, t = "literal"] in
382382
return z
383383
}
384384
}

0 commit comments

Comments
 (0)