From dbcdd273af63a78ce542468978629fee2b3eab50 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 13:15:42 +0100 Subject: [PATCH 1/8] Unified: Add CFG tests for Swift `fallthrough` statement Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- .../controlflow/basicblock-slices.expected | 50 ++++++++++++++++ .../library-tests/controlflow/cfg.expected | 34 +++++++++++ .../controlflow/fallthrough.swift | 57 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 unified/ql/test/library-tests/controlflow/fallthrough.swift diff --git a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected index 6915dcd76534..064c47837ba3 100644 --- a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected +++ b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected @@ -1,54 +1,104 @@ | 1 | cfg.swift:1:1:635:1 | Block | 'Block -V var topLevelDecl -V topLevelDecl -> Int -> 0' | +| 1 | fallthrough.swift:1:1:57:1 | Block | 'Block -V func fallthroughChain -V fallthroughChain' | +| 1 | fallthrough.swift:1:25:1:25 | x | 'x -> flag -> Block' | | 2 | cfg.swift:2:1:2:1 | 0 | '0' | +| 2 | fallthrough.swift:2:3:18:3 | SwitchExpr | 'SwitchExpr -V x' | | 3 | cfg.swift:3:1:3:12 | topLevelDecl | 'topLevelDecl -> 1 -^ ... + ...' | +| 3 | fallthrough.swift:3:3:9:9 | SwitchCase | 'SwitchCase -V 0' | +| 4 | fallthrough.swift:4:5:9:9 | Block | 'Block -V IfExpr -V flag' | +| 4 | fallthrough.swift:4:13:7:5 | Block | 'Block' | | 5 | cfg.swift:5:1:5:37 | func returnZero | 'func returnZero -V returnZero' | | 5 | cfg.swift:5:26:5:37 | Block | 'Block -V 0 -^ ReturnExpr' | +| 5 | fallthrough.swift:5:7:5:17 | | '' | +| 6 | fallthrough.swift:6:7:6:11 | print | 'print -> Argument -V "unreachable" -^ print(...)' | | 7 | cfg.swift:7:1:7:10 | returnZero | 'returnZero -^ returnZero(...)' | | 8 | cfg.swift:8:1:8:6 | Double | 'Double -> Argument -V topLevelDecl -^ Double(...)' | +| 8 | fallthrough.swift:8:5:8:9 | print | 'print -> Argument -V "stay in first case" -^ print(...)' | +| 9 | fallthrough.swift:9:5:9:9 | BreakExpr | 'BreakExpr' | | 10 | cfg.swift:10:1:13:1 | enum MyError | 'enum MyError -V MyError -> BaseType -V Error' | +| 10 | fallthrough.swift:10:3:12:15 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' | | 11 | cfg.swift:11:10:11:15 | MyError.error1 | 'MyError.error1 -V error1 -> MyError.error2 -V error2' | +| 11 | fallthrough.swift:11:5:12:15 | Block | 'Block -V print -> Argument -V "second case" -^ print(...)' | | 12 | cfg.swift:12:10:12:31 | MyError.error3 | 'MyError.error3 -V error3 -^ MyError.error3.(constructor)' | | 12 | cfg.swift:12:17:12:25 | withParam | 'withParam -? Block' | +| 12 | fallthrough.swift:12:5:12:15 | | '' | +| 13 | fallthrough.swift:13:3:15:15 | SwitchCase | 'SwitchCase -V 2' | +| 14 | fallthrough.swift:14:5:15:15 | Block | 'Block -V print -> Argument -V "third case" -^ print(...)' | | 15 | cfg.swift:15:1:17:1 | func isZero | 'func isZero -V isZero' | | 15 | cfg.swift:15:13:15:13 | x | 'x -> Block' | +| 15 | fallthrough.swift:15:5:15:15 | | '' | | 16 | cfg.swift:16:10:16:10 | x | 'x -> 0 -^ ... == ... -^ ReturnExpr' | +| 16 | fallthrough.swift:16:3:17:25 | SwitchCase | 'SwitchCase' | +| 17 | fallthrough.swift:17:5:17:25 | Block | 'Block -V print -> Argument -V "default case" -^ print(...)' | | 19 | cfg.swift:19:1:26:1 | func mightThrow | 'func mightThrow -V mightThrow' | | 19 | cfg.swift:19:17:19:17 | x | 'x -> Block' | +| 19 | fallthrough.swift:19:3:19:7 | print | 'print -> Argument -V "after switch" -^ print(...)' | | 20 | cfg.swift:20:3:22:3 | GuardIfStmt | 'GuardIfStmt -V x -> 0 -^ ... >= ...' | | 20 | cfg.swift:20:21:22:3 | Block | 'Block' | | 21 | cfg.swift:21:11:21:17 | MyError | 'MyError -^ ... .error1 -^ ThrowExpr' | +| 22 | fallthrough.swift:22:1:37:1 | func nestedFallthrough | 'func nestedFallthrough -V nestedFallthrough' | +| 22 | fallthrough.swift:22:26:22:26 | x | 'x -> y -> Block' | | 23 | cfg.swift:23:3:25:3 | GuardIfStmt | 'GuardIfStmt -V x -> 0 -^ ... <= ...' | | 23 | cfg.swift:23:21:25:3 | Block | 'Block' | +| 23 | fallthrough.swift:23:3:35:3 | SwitchExpr | 'SwitchExpr -V x' | | 24 | cfg.swift:24:11:24:17 | MyError | 'MyError -^ ... .error3 -> Argument -V x -> 1 -^ ... + ... -^ ... .error3(...) -^ ThrowExpr' | +| 24 | fallthrough.swift:24:3:32:15 | SwitchCase | 'SwitchCase -V 0' | +| 25 | fallthrough.swift:25:5:32:15 | Block | 'Block -V SwitchExpr -V y' | +| 26 | fallthrough.swift:26:5:27:17 | SwitchCase | 'SwitchCase -V 0' | +| 27 | fallthrough.swift:27:7:27:17 | Block | 'Block -V ' | | 28 | cfg.swift:28:1:45:1 | func tryCatch | 'func tryCatch -V tryCatch' | | 28 | cfg.swift:28:15:28:15 | x | 'x -> Block' | +| 28 | fallthrough.swift:28:5:29:28 | SwitchCase | 'SwitchCase' | | 29 | cfg.swift:29:3:43:3 | TryExpr | 'TryExpr -V Block' | +| 29 | fallthrough.swift:29:7:29:28 | Block | 'Block -V print -> Argument -V "inner default" -^ print(...)' | | 30 | cfg.swift:30:5:30:24 | try ... | 'try ...' | | 30 | cfg.swift:30:9:30:18 | mightThrow | 'mightThrow -> Argument -V 0 -^ mightThrow(...)' | | 31 | cfg.swift:31:5:31:9 | print | 'print -> Argument -V "Did not throw." -^ print(...)' | +| 31 | fallthrough.swift:31:5:31:9 | print | 'print -> Argument -V "after inner switch" -^ print(...)' | | 32 | cfg.swift:32:10:32:19 | mightThrow | 'mightThrow -> Argument -V 0 -^ mightThrow(...) -^ try! ...' | +| 32 | fallthrough.swift:32:5:32:15 | | '' | | 33 | cfg.swift:33:5:33:9 | print | 'print -> Argument -V "Still did not throw." -^ print(...)' | +| 33 | fallthrough.swift:33:3:34:26 | SwitchCase | 'SwitchCase' | +| 34 | fallthrough.swift:34:5:34:26 | Block | 'Block -V print -> Argument -V "outer default" -^ print(...)' | | 35 | cfg.swift:35:5:37:3 | CatchClause | 'CatchClause -V MyError -^ ... .error1 -> isZero -> Argument -V x -^ isZero(...) -? MyError -^ ... .error2 -^ ConditionalPattern -^ OrPattern' | | 35 | cfg.swift:35:62:37:3 | Block | 'Block' | | 36 | cfg.swift:36:12:36:12 | 0 | '0 -^ ReturnExpr' | +| 36 | fallthrough.swift:36:3:36:7 | print | 'print -> Argument -V "after outer switch" -^ print(...)' | | 37 | cfg.swift:37:5:39:3 | CatchClause | 'CatchClause -V MyError -^ ... .error3 -> Argument -V withParam -^ ExprPattern -^ ... .error3(...)' | | 37 | cfg.swift:37:41:39:3 | Block | 'Block' | | 38 | cfg.swift:38:12:38:20 | withParam | 'withParam -^ ReturnExpr' | | 39 | cfg.swift:39:5:41:3 | CatchClause | 'CatchClause -V ' | | 39 | cfg.swift:39:22:41:3 | Block | 'Block' | +| 39 | fallthrough.swift:39:1:57:1 | func fallthroughWithDefer | 'func fallthroughWithDefer -V fallthroughWithDefer' | +| 39 | fallthrough.swift:39:29:39:29 | x | 'x -> flag -> Block' | | 40 | cfg.swift:40:5:40:9 | print | 'print -> Argument -V "MyError" -^ print(...)' | +| 40 | fallthrough.swift:40:3:55:3 | SwitchExpr | 'SwitchExpr -V x' | | 41 | cfg.swift:41:5:43:3 | CatchClause | 'CatchClause -V Block' | +| 41 | fallthrough.swift:41:3:50:5 | SwitchCase | 'SwitchCase -V 0' | | 42 | cfg.swift:42:5:42:9 | print | 'print -> Argument -V Unknown error -> interpolation -> Argument -V error -^ interpolation(...) -> -^ StringInterpolationExpr -^ print(...)' | +| 42 | fallthrough.swift:42:5:50:5 | Block | 'Block -V DeferStmt' | +| 42 | fallthrough.swift:42:11:44:5 | Block | 'Block' | +| 43 | fallthrough.swift:43:7:43:11 | print | 'print -> Argument -V "outer defer" -^ print(...)' | | 44 | cfg.swift:44:10:44:10 | 0 | '0 -^ ReturnExpr' | +| 45 | fallthrough.swift:45:5:50:5 | TryExpr | 'TryExpr -V Block' | +| 46 | fallthrough.swift:46:7:48:7 | DeferStmt | 'DeferStmt' | +| 46 | fallthrough.swift:46:13:48:7 | Block | 'Block' | | 47 | cfg.swift:47:1:51:1 | func createClosure1 | 'func createClosure1 -V createClosure1' | | 47 | cfg.swift:47:21:47:21 | s | 's -> Block' | +| 47 | fallthrough.swift:47:9:47:13 | print | 'print -> Argument -V "inner defer" -^ print(...)' | | 48 | cfg.swift:48:10:50:3 | FunctionExpr | 'FunctionExpr -^ ReturnExpr' | | 49 | cfg.swift:49:5:49:17 | Block | 'Block -V s -> "" -^ ... + ... -^ ReturnExpr' | +| 49 | fallthrough.swift:49:7:49:17 | | '' | +| 51 | fallthrough.swift:51:3:52:22 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' | +| 52 | fallthrough.swift:52:5:52:22 | Block | 'Block -V print -> Argument -V "next case" -^ print(...)' | | 53 | cfg.swift:53:1:58:1 | func createClosure2 | 'func createClosure2 -V createClosure2' | | 53 | cfg.swift:53:21:53:21 | x | 'x -> Block' | +| 53 | fallthrough.swift:53:3:54:9 | SwitchCase | 'SwitchCase' | | 54 | cfg.swift:54:3:56:3 | func f | 'func f -V f' | | 54 | cfg.swift:54:10:54:10 | y | 'y -> Block' | +| 54 | fallthrough.swift:54:5:54:9 | Block | 'Block -V BreakExpr' | | 55 | cfg.swift:55:12:55:12 | x | 'x -> y -^ ... + ... -^ ReturnExpr' | +| 56 | fallthrough.swift:56:3:56:7 | print | 'print -> Argument -V "after deferred fallthrough" -^ print(...)' | | 57 | cfg.swift:57:10:57:10 | f | 'f -^ ReturnExpr' | | 60 | cfg.swift:60:1:64:1 | func createClosure3 | 'func createClosure3 -V createClosure3' | | 60 | cfg.swift:60:21:60:21 | x | 'x -> Block' | diff --git a/unified/ql/test/library-tests/controlflow/cfg.expected b/unified/ql/test/library-tests/controlflow/cfg.expected index 79aeb2956ca0..59cc374a8a0e 100644 --- a/unified/ql/test/library-tests/controlflow/cfg.expected +++ b/unified/ql/test/library-tests/controlflow/cfg.expected @@ -3,6 +3,10 @@ bbContinues | cfg.swift:183:3:183:3 | DeferStmt | 'DeferStmt goto DeferStmt(+4)' | | cfg.swift:184:5:184:14 | print(...) | 'print(...) goto Block(-7)' | | cfg.swift:190:7:190:16 | print(...) | 'print(...) goto Block(-7)' | +| fallthrough.swift:42:5:42:5 | DeferStmt | 'DeferStmt goto TryExpr(+3)' | +| fallthrough.swift:46:7:46:7 | DeferStmt | 'DeferStmt goto (+3)' | +| fallthrough.swift:47:9:47:28 | print(...) | 'print(...) goto Block(-5)' | +| fallthrough.swift:49:7:49:17 | | ' goto Block(-3)' | bbStep | cfg.swift:20:9:20:14 | ... >= ... | '... >= ... : false -> Block(+0)' | | cfg.swift:20:9:20:14 | ... >= ... | '... >= ... : true -> GuardIfStmt(+3)' | @@ -167,6 +171,34 @@ bbStep | cfg.swift:627:10:627:27 | ConditionalPattern | 'ConditionalPattern : no-match -> SwitchCase(+2)' | | cfg.swift:629:10:629:16 | ... .error1 | '... .error1 : match -> Block(+1)' | | cfg.swift:629:10:629:16 | ... .error1 | '... .error1 : no-match -> SwitchCase(+2)' | +| fallthrough.swift:3:8:3:8 | 0 | '0 : match -> Block(+1)' | +| fallthrough.swift:3:8:3:8 | 0 | '0 : no-match -> SwitchCase(+7)' | +| fallthrough.swift:4:8:4:11 | flag | 'flag : false -> print(+4)' | +| fallthrough.swift:4:8:4:11 | flag | 'flag : true -> Block(+0)' | +| fallthrough.swift:6:7:6:26 | print(...) | 'print(...) : successor -> print(+2)' | +| fallthrough.swift:9:5:9:9 | BreakExpr | 'BreakExpr : break -> print(+10)' | +| fallthrough.swift:10:8:10:19 | ConditionalPattern | 'ConditionalPattern : match -> Block(+1)' | +| fallthrough.swift:10:8:10:19 | ConditionalPattern | 'ConditionalPattern : no-match -> SwitchCase(+3)' | +| fallthrough.swift:12:5:12:15 | | ' : successor -> print(+7)' | +| fallthrough.swift:13:8:13:8 | 2 | '2 : match -> Block(+1)' | +| fallthrough.swift:13:8:13:8 | 2 | '2 : no-match -> SwitchCase(+3)' | +| fallthrough.swift:15:5:15:15 | | ' : successor -> print(+4)' | +| fallthrough.swift:17:5:17:25 | print(...) | 'print(...) : successor -> print(+2)' | +| fallthrough.swift:24:8:24:8 | 0 | '0 : match -> Block(+1)' | +| fallthrough.swift:24:8:24:8 | 0 | '0 : no-match -> SwitchCase(+9)' | +| fallthrough.swift:26:10:26:10 | 0 | '0 : match -> Block(+1)' | +| fallthrough.swift:26:10:26:10 | 0 | '0 : no-match -> SwitchCase(+2)' | +| fallthrough.swift:27:7:27:17 | | ' : successor -> print(+4)' | +| fallthrough.swift:29:7:29:28 | print(...) | 'print(...) : successor -> print(+2)' | +| fallthrough.swift:32:5:32:15 | | ' : successor -> print(+4)' | +| fallthrough.swift:34:5:34:26 | print(...) | 'print(...) : successor -> print(+2)' | +| fallthrough.swift:41:8:41:8 | 0 | '0 : match -> Block(+1)' | +| fallthrough.swift:41:8:41:8 | 0 | '0 : no-match -> SwitchCase(+10)' | +| fallthrough.swift:43:7:43:26 | print(...) | 'print(...) : successor -> print(+13)' | +| fallthrough.swift:51:8:51:19 | ConditionalPattern | 'ConditionalPattern : match -> Block(+1)' | +| fallthrough.swift:51:8:51:19 | ConditionalPattern | 'ConditionalPattern : no-match -> SwitchCase(+2)' | +| fallthrough.swift:52:5:52:22 | print(...) | 'print(...) : successor -> print(+4)' | +| fallthrough.swift:54:5:54:9 | BreakExpr | 'BreakExpr : break -> print(+2)' | noCfg | cfg.swift:47:42:47:47 | String | | cfg.swift:53:34:53:34 | _ | @@ -192,3 +224,5 @@ nonSimple | cfg.swift:12:17:12:25 | withParam | 'withParam -? Block' | | cfg.swift:35:5:35:5 | CatchClause | 'CatchClause -V MyError -^ ... .error1 -> isZero -> Argument -V x -^ isZero(...) -? MyError -^ ... .error2 -^ ConditionalPattern -^ OrPattern' | | cfg.swift:627:5:627:5 | SwitchCase | 'SwitchCase -V flag -? . -^ ... .error1 -^ ConditionalPattern' | +| fallthrough.swift:10:3:10:3 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' | +| fallthrough.swift:51:3:51:3 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' | diff --git a/unified/ql/test/library-tests/controlflow/fallthrough.swift b/unified/ql/test/library-tests/controlflow/fallthrough.swift new file mode 100644 index 000000000000..f96ceb3f0ec4 --- /dev/null +++ b/unified/ql/test/library-tests/controlflow/fallthrough.swift @@ -0,0 +1,57 @@ +func fallthroughChain(_ x: Int, _ flag: Bool) { + switch x { + case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+7)' + if flag { // $ bbStep='flag : false -> print(+4)' bbStep='flag : true -> Block(+0)' + fallthrough + print("unreachable") // $ bbStep='print(...) : successor -> print(+2)' + } + print("stay in first case") + break // $ bbStep='BreakExpr : break -> print(+10)' + case 1 where flag: // $ bbStep='ConditionalPattern : match -> Block(+1)' bbStep='ConditionalPattern : no-match -> SwitchCase(+3)' nonSimple='SwitchCase -V flag -? 1 -^ ConditionalPattern' + print("second case") + fallthrough // $ bbStep=' : successor -> print(+7)' + case 2: // $ bbStep='2 : match -> Block(+1)' bbStep='2 : no-match -> SwitchCase(+3)' + print("third case") + fallthrough // $ bbStep=' : successor -> print(+4)' + default: + print("default case") // $ bbStep='print(...) : successor -> print(+2)' + } + print("after switch") +} + +func nestedFallthrough(_ x: Int, _ y: Int) { + switch x { + case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+9)' + switch y { + case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+2)' + fallthrough // $ bbStep=' : successor -> print(+4)' + default: + print("inner default") // $ bbStep='print(...) : successor -> print(+2)' + } + print("after inner switch") + fallthrough // $ bbStep=' : successor -> print(+4)' + default: + print("outer default") // $ bbStep='print(...) : successor -> print(+2)' + } + print("after outer switch") +} + +func fallthroughWithDefer(_ x: Int, _ flag: Bool) { + switch x { + case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+10)' + defer { // $ bbContinues='DeferStmt goto TryExpr(+3)' + print("outer defer") // $ bbStep='print(...) : successor -> print(+13)' + } + do { + defer { // $ bbContinues='DeferStmt goto (+3)' + print("inner defer") // $ bbContinues='print(...) goto Block(-5)' + } + fallthrough // $ bbContinues=' goto Block(-3)' + } + case 1 where flag: // $ bbStep='ConditionalPattern : match -> Block(+1)' bbStep='ConditionalPattern : no-match -> SwitchCase(+2)' nonSimple='SwitchCase -V flag -? 1 -^ ConditionalPattern' + print("next case") // $ bbStep='print(...) : successor -> print(+4)' + default: + break // $ bbStep='BreakExpr : break -> print(+2)' + } + print("after deferred fallthrough") +} From e8ad730fd5682c0788ec2889ecc40599113e9ada Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 13:52:14 +0100 Subject: [PATCH 2/8] Go: Add CFG `fallthrough` tests for empty cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- .../ControlFlowNode_getASuccessor.expected | 75 +++++++++++++++++++ .../ControlFlowGraph/fallthrough.go | 21 ++++++ 2 files changed, 96 insertions(+) create mode 100644 go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/fallthrough.go diff --git a/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected b/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected index ae8d5d7e77c4..63583896a9f7 100644 --- a/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected +++ b/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected @@ -1194,6 +1194,81 @@ | exprs.go:94:15:94:15 | y | exprs.go:94:15:94:15 | After y [false] | | exprs.go:94:15:94:15 | y | exprs.go:94:15:94:15 | After y [true] | | exprs.go:94:21:94:21 | z | exprs.go:94:9:94:21 | After ...\|\|... | +| fallthrough.go:0:0:0:0 | After fallthrough.go | fallthrough.go:0:0:0:0 | Normal Exit | +| fallthrough.go:0:0:0:0 | Entry | fallthrough.go:0:0:0:0 | fallthrough.go | +| fallthrough.go:0:0:0:0 | Normal Exit | fallthrough.go:0:0:0:0 | Exit | +| fallthrough.go:0:0:0:0 | fallthrough.go | fallthrough.go:3:1:12:1 | function declaration | +| fallthrough.go:3:1:12:1 | Entry | fallthrough.go:3:29:3:29 | x | +| fallthrough.go:3:1:12:1 | Exceptional Exit | fallthrough.go:3:1:12:1 | Exit | +| fallthrough.go:3:1:12:1 | Normal Exit | fallthrough.go:3:1:12:1 | Exit | +| fallthrough.go:3:1:12:1 | function declaration | fallthrough.go:14:1:21:1 | function declaration | +| fallthrough.go:3:29:3:29 | x | fallthrough.go:3:36:12:1 | block statement | +| fallthrough.go:3:36:12:1 | After block statement | fallthrough.go:3:1:12:1 | Normal Exit | +| fallthrough.go:3:36:12:1 | block statement | fallthrough.go:4:2:10:2 | expression-switch statement | +| fallthrough.go:4:2:10:2 | After expression-switch statement | fallthrough.go:11:2:11:13 | expression statement | +| fallthrough.go:4:2:10:2 | expression-switch statement | fallthrough.go:4:9:4:9 | x | +| fallthrough.go:4:9:4:9 | x | fallthrough.go:5:2:6:13 | case clause | +| fallthrough.go:5:2:6:13 | After case clause [match] | fallthrough.go:6:3:6:13 | fallthrough statement | +| fallthrough.go:5:2:6:13 | After case clause [no-match] | fallthrough.go:7:2:7:8 | case clause | +| fallthrough.go:5:2:6:13 | case clause | fallthrough.go:5:7:5:7 | 0 | +| fallthrough.go:5:7:5:7 | 0 | fallthrough.go:5:7:5:7 | After 0 [match] | +| fallthrough.go:5:7:5:7 | 0 | fallthrough.go:5:7:5:7 | After 0 [no-match] | +| fallthrough.go:5:7:5:7 | After 0 [match] | fallthrough.go:5:2:6:13 | After case clause [match] | +| fallthrough.go:5:7:5:7 | After 0 [no-match] | fallthrough.go:5:2:6:13 | After case clause [no-match] | +| fallthrough.go:6:3:6:13 | fallthrough statement | fallthrough.go:4:2:10:2 | After expression-switch statement | +| fallthrough.go:7:2:7:8 | After case clause [match] | fallthrough.go:4:2:10:2 | After expression-switch statement | +| fallthrough.go:7:2:7:8 | After case clause [no-match] | fallthrough.go:8:2:9:13 | case clause | +| fallthrough.go:7:2:7:8 | case clause | fallthrough.go:7:7:7:7 | 1 | +| fallthrough.go:7:7:7:7 | 1 | fallthrough.go:7:7:7:7 | After 1 [match] | +| fallthrough.go:7:7:7:7 | 1 | fallthrough.go:7:7:7:7 | After 1 [no-match] | +| fallthrough.go:7:7:7:7 | After 1 [match] | fallthrough.go:7:2:7:8 | After case clause [match] | +| fallthrough.go:7:7:7:7 | After 1 [no-match] | fallthrough.go:7:2:7:8 | After case clause [no-match] | +| fallthrough.go:8:2:9:13 | After case clause [match] | fallthrough.go:9:3:9:13 | expression statement | +| fallthrough.go:8:2:9:13 | case clause | fallthrough.go:8:2:9:13 | After case clause [match] | +| fallthrough.go:9:3:9:7 | test5 | fallthrough.go:9:9:9:12 | true | +| fallthrough.go:9:3:9:13 | After call to test5 | fallthrough.go:9:3:9:13 | After expression statement | +| fallthrough.go:9:3:9:13 | After expression statement | fallthrough.go:4:2:10:2 | After expression-switch statement | +| fallthrough.go:9:3:9:13 | Before call to test5 | fallthrough.go:9:3:9:7 | test5 | +| fallthrough.go:9:3:9:13 | call to test5 | fallthrough.go:3:1:12:1 | Exceptional Exit | +| fallthrough.go:9:3:9:13 | call to test5 | fallthrough.go:9:3:9:13 | After call to test5 | +| fallthrough.go:9:3:9:13 | expression statement | fallthrough.go:9:3:9:13 | Before call to test5 | +| fallthrough.go:9:9:9:12 | true | fallthrough.go:9:3:9:13 | call to test5 | +| fallthrough.go:11:2:11:6 | test5 | fallthrough.go:11:8:11:12 | false | +| fallthrough.go:11:2:11:13 | After call to test5 | fallthrough.go:11:2:11:13 | After expression statement | +| fallthrough.go:11:2:11:13 | After expression statement | fallthrough.go:3:36:12:1 | After block statement | +| fallthrough.go:11:2:11:13 | Before call to test5 | fallthrough.go:11:2:11:6 | test5 | +| fallthrough.go:11:2:11:13 | call to test5 | fallthrough.go:3:1:12:1 | Exceptional Exit | +| fallthrough.go:11:2:11:13 | call to test5 | fallthrough.go:11:2:11:13 | After call to test5 | +| fallthrough.go:11:2:11:13 | expression statement | fallthrough.go:11:2:11:13 | Before call to test5 | +| fallthrough.go:11:8:11:12 | false | fallthrough.go:11:2:11:13 | call to test5 | +| fallthrough.go:14:1:21:1 | Entry | fallthrough.go:14:32:14:32 | x | +| fallthrough.go:14:1:21:1 | Exceptional Exit | fallthrough.go:14:1:21:1 | Exit | +| fallthrough.go:14:1:21:1 | Normal Exit | fallthrough.go:14:1:21:1 | Exit | +| fallthrough.go:14:1:21:1 | function declaration | fallthrough.go:0:0:0:0 | After fallthrough.go | +| fallthrough.go:14:32:14:32 | x | fallthrough.go:14:39:21:1 | block statement | +| fallthrough.go:14:39:21:1 | After block statement | fallthrough.go:14:1:21:1 | Normal Exit | +| fallthrough.go:14:39:21:1 | block statement | fallthrough.go:15:2:19:2 | expression-switch statement | +| fallthrough.go:15:2:19:2 | After expression-switch statement | fallthrough.go:20:2:20:13 | expression statement | +| fallthrough.go:15:2:19:2 | expression-switch statement | fallthrough.go:15:9:15:9 | x | +| fallthrough.go:15:9:15:9 | x | fallthrough.go:16:2:17:13 | case clause | +| fallthrough.go:16:2:17:13 | After case clause [match] | fallthrough.go:17:3:17:13 | fallthrough statement | +| fallthrough.go:16:2:17:13 | After case clause [no-match] | fallthrough.go:18:2:18:9 | case clause | +| fallthrough.go:16:2:17:13 | case clause | fallthrough.go:16:7:16:7 | 0 | +| fallthrough.go:16:7:16:7 | 0 | fallthrough.go:16:7:16:7 | After 0 [match] | +| fallthrough.go:16:7:16:7 | 0 | fallthrough.go:16:7:16:7 | After 0 [no-match] | +| fallthrough.go:16:7:16:7 | After 0 [match] | fallthrough.go:16:2:17:13 | After case clause [match] | +| fallthrough.go:16:7:16:7 | After 0 [no-match] | fallthrough.go:16:2:17:13 | After case clause [no-match] | +| fallthrough.go:17:3:17:13 | fallthrough statement | fallthrough.go:15:2:19:2 | After expression-switch statement | +| fallthrough.go:18:2:18:9 | After case clause [match] | fallthrough.go:15:2:19:2 | After expression-switch statement | +| fallthrough.go:18:2:18:9 | case clause | fallthrough.go:18:2:18:9 | After case clause [match] | +| fallthrough.go:20:2:20:6 | test5 | fallthrough.go:20:8:20:12 | false | +| fallthrough.go:20:2:20:13 | After call to test5 | fallthrough.go:20:2:20:13 | After expression statement | +| fallthrough.go:20:2:20:13 | After expression statement | fallthrough.go:14:39:21:1 | After block statement | +| fallthrough.go:20:2:20:13 | Before call to test5 | fallthrough.go:20:2:20:6 | test5 | +| fallthrough.go:20:2:20:13 | call to test5 | fallthrough.go:14:1:21:1 | Exceptional Exit | +| fallthrough.go:20:2:20:13 | call to test5 | fallthrough.go:20:2:20:13 | After call to test5 | +| fallthrough.go:20:2:20:13 | expression statement | fallthrough.go:20:2:20:13 | Before call to test5 | +| fallthrough.go:20:8:20:12 | false | fallthrough.go:20:2:20:13 | call to test5 | | generic.go:0:0:0:0 | After generic.go | generic.go:0:0:0:0 | Normal Exit | | generic.go:0:0:0:0 | Entry | generic.go:0:0:0:0 | generic.go | | generic.go:0:0:0:0 | Normal Exit | generic.go:0:0:0:0 | Exit | diff --git a/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/fallthrough.go b/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/fallthrough.go new file mode 100644 index 000000000000..00f8c19b69b6 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/fallthrough.go @@ -0,0 +1,21 @@ +package main + +func fallthroughToEmptyCase(x int) { + switch x { + case 0: + fallthrough + case 1: + default: + test5(true) + } + test5(false) +} + +func fallthroughToEmptyDefault(x int) { + switch x { + case 0: + fallthrough + default: + } + test5(false) +} From 55e5e1f943f8b0cd9f3e6fcfcd51b949a5ed02dd Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 13:18:05 +0100 Subject: [PATCH 3/8] Unified: Extract Swift `fallthrough` statements Add a `fallthrough` statement node, map Swift syntax to it, and regenerate the AST library, database schema, and extractor corpus output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- unified/extractor/ast_types.yml | 4 +++ .../extractor/src/languages/swift/swift.rs | 1 + .../swift/control-flow/fallthrough.output | 2 +- .../ql/lib/codeql/unified/internal/Ast.qll | 8 +++++ unified/ql/lib/unified.dbscheme | 33 ++++++++++--------- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/unified/extractor/ast_types.yml b/unified/extractor/ast_types.yml index 5cf5538e1a58..aeb9164c94b2 100644 --- a/unified/extractor/ast_types.yml +++ b/unified/extractor/ast_types.yml @@ -68,6 +68,7 @@ supertypes: - do_while_stmt - defer_stmt - labeled_stmt + - fallthrough_stmt callable: subtypes: - top_level @@ -302,6 +303,9 @@ named: continue_expr: label_name_node?: identifier + # Transfer control directly to the next switch case's body. + fallthrough_stmt: + # A labeled statement, such as `outer: for ... { ... }`. The labeled # statement appears as the `stmt` field; `break`/`continue` may target # the label. diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 5b08e45ba96b..dfa74833ee6c 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -840,6 +840,7 @@ fn translation_rules() -> Vec> { rule!((returnStmt expression: _? @val) => (return_expr value: {val})), rule!((breakStmt label: _? @@lbl) => (break_expr label_name_node: [(identifier #{lbl})])), rule!((continueStmt label: _? @@lbl) => (continue_expr label_name_node: [(identifier #{lbl})])), + rule!((fallThroughStmt) => (fallthrough_stmt)), rule!((throwStmt expression: @val) => (throw_expr value: {val})), // ---- Closures ---- // A closure (`{ (x: Int) -> Int in … }`) becomes a `function_expr`. The diff --git a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output index d66f8c856e02..2e3c3773ff2b 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output +++ b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output @@ -103,7 +103,7 @@ top_level source="⟨body⟩" pattern: int_literal "1" source="1" body: block source="⟨stmt⟩" - stmt: unsupported_node "fallthrough" source="fallthrough" + stmt: fallthrough_stmt "fallthrough" source="fallthrough" switch_case source="default:\n ⟨body⟩" body: block source="⟨stmt⟩" diff --git a/unified/ql/lib/codeql/unified/internal/Ast.qll b/unified/ql/lib/codeql/unified/internal/Ast.qll index dc484607609a..2d8814ca52bd 100644 --- a/unified/ql/lib/codeql/unified/internal/Ast.qll +++ b/unified/ql/lib/codeql/unified/internal/Ast.qll @@ -655,6 +655,12 @@ module Unified { } } + /** A class representing `fallthrough_stmt` tokens. */ + class FallthroughStmt extends @unified_token_fallthrough_stmt, F::Stmt, F::Token { + /** Gets the name of the primary QL class for this element. */ + final override string getAPrimaryQlClass() { result = "FallthroughStmt" } + } + /** A class representing `fixity` tokens. */ class Fixity extends @unified_token_fixity, F::AstNode, F::Token { /** Gets the name of the primary QL class for this element. */ @@ -1998,6 +2004,8 @@ module UnifiedFinal { final class ExprPattern = F::ExprPattern; + final class FallthroughStmt = F::FallthroughStmt; + final class Fixity = F::Fixity; final class FloatLiteral = F::FloatLiteral; diff --git a/unified/ql/lib/unified.dbscheme b/unified/ql/lib/unified.dbscheme index 5d7863737417..248bbdb74d16 100644 --- a/unified/ql/lib/unified.dbscheme +++ b/unified/ql/lib/unified.dbscheme @@ -789,7 +789,7 @@ unified_return_expr_def( unique int id: @unified_return_expr ); -@unified_stmt = @unified_accessor_declaration | @unified_class_like_declaration | @unified_constructor_declaration | @unified_defer_stmt | @unified_destructor_declaration | @unified_do_while_stmt | @unified_expr | @unified_for_each_stmt | @unified_function_declaration | @unified_guard_if_stmt | @unified_import_declaration | @unified_labeled_stmt | @unified_operator_syntax_declaration | @unified_type_alias_declaration | @unified_variable_declaration | @unified_while_stmt +@unified_stmt = @unified_accessor_declaration | @unified_class_like_declaration | @unified_constructor_declaration | @unified_defer_stmt | @unified_destructor_declaration | @unified_do_while_stmt | @unified_expr | @unified_for_each_stmt | @unified_function_declaration | @unified_guard_if_stmt | @unified_import_declaration | @unified_labeled_stmt | @unified_operator_syntax_declaration | @unified_token_fallthrough_stmt | @unified_type_alias_declaration | @unified_variable_declaration | @unified_while_stmt #keyset[unified_string_interpolation_expr, index] unified_string_interpolation_expr_element( @@ -1020,21 +1020,22 @@ case @unified_token.kind of | 2 = @unified_token_boolean_literal | 3 = @unified_token_builtin_expr | 4 = @unified_token_empty_expr -| 5 = @unified_token_fixity -| 6 = @unified_token_float_literal -| 7 = @unified_token_identifier -| 8 = @unified_token_ignore_pattern -| 9 = @unified_token_inferred_type_expr -| 10 = @unified_token_infix_operator -| 11 = @unified_token_int_literal -| 12 = @unified_token_modifier -| 13 = @unified_token_postfix_operator -| 14 = @unified_token_prefix_operator -| 15 = @unified_token_regex_literal -| 16 = @unified_token_string_literal -| 17 = @unified_token_super_expr -| 18 = @unified_token_unhandled_node -| 19 = @unified_token_unsupported_node +| 5 = @unified_token_fallthrough_stmt +| 6 = @unified_token_fixity +| 7 = @unified_token_float_literal +| 8 = @unified_token_identifier +| 9 = @unified_token_ignore_pattern +| 10 = @unified_token_inferred_type_expr +| 11 = @unified_token_infix_operator +| 12 = @unified_token_int_literal +| 13 = @unified_token_modifier +| 14 = @unified_token_postfix_operator +| 15 = @unified_token_prefix_operator +| 16 = @unified_token_regex_literal +| 17 = @unified_token_string_literal +| 18 = @unified_token_super_expr +| 19 = @unified_token_unhandled_node +| 20 = @unified_token_unsupported_node ; From d376b622f96e19c8d78f74d0d68eee9639eab1d4 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 13:30:54 +0100 Subject: [PATCH 4/8] Shared: Add explicit `fallthrough` statement support to CFG library Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- .../codeql/controlflow/ControlFlowGraph.qll | 26 +++++++++++++++++++ .../codeql/controlflow/SuccessorType.qll | 12 +++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll b/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll index 78d894c01a36..4f3d739bd848 100644 --- a/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll +++ b/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll @@ -179,6 +179,14 @@ signature module AstSig { */ class ContinueStmt extends Stmt; + /** + * A `fallthrough` statement. + * + * Fallthrough statements complete abruptly and continue at the next switch + * case's body, without evaluating its pattern or guard. + */ + class FallthroughStmt extends Stmt; + /** * A `goto` statement. * @@ -579,6 +587,8 @@ module Make0 Ast> { or n instanceof ContinueStmt or + n instanceof FallthroughStmt + or n instanceof GotoStmt or n instanceof Expr and @@ -743,6 +753,8 @@ module Make0 Ast> { or n instanceof ContinueStmt or + n instanceof FallthroughStmt + or n instanceof GotoStmt or n instanceof ReturnStmt @@ -1288,6 +1300,9 @@ module Make0 Ast> { ast instanceof ContinueStmt and st instanceof ContinueSuccessor or + ast instanceof FallthroughStmt and + st instanceof FallthroughSuccessor + or ast instanceof GotoStmt and st instanceof GotoSuccessor | @@ -1396,6 +1411,17 @@ module Make0 Ast> { ) ) or + exists(Switch switch, int index, Case nextCase | + ast = getCaseBodyElement(switch.getCase(index), _) and + nextCase = switch.getCase(index + 1) and + c.asSimpleAbruptCompletion() instanceof FallthroughSuccessor + | + n.isBefore(getFirstCaseBodyElement(nextCase)) + or + not exists(getFirstCaseBodyElement(nextCase)) and + n.isAfter(switch) + ) + or exists(LabeledStmt target, Input1::Label l | ast = target.getStmt() and Input1::hasLabel(target, l) and diff --git a/shared/controlflow/codeql/controlflow/SuccessorType.qll b/shared/controlflow/codeql/controlflow/SuccessorType.qll index 2e6666d2c204..cd331ee59399 100644 --- a/shared/controlflow/codeql/controlflow/SuccessorType.qll +++ b/shared/controlflow/codeql/controlflow/SuccessorType.qll @@ -18,6 +18,7 @@ * \- JumpSuccessor * |- BreakSuccessor * |- ContinueSuccessor + * |- FallthroughSuccessor * |- GotoSuccessor * |- RedoSuccessor // rare, used in Ruby * \- RetrySuccessor // rare, used in Ruby @@ -71,6 +72,7 @@ private newtype TSuccessorType = TExitSuccessor() or TBreakSuccessor() or TContinueSuccessor() or + TFallthroughSuccessor() or TGotoSuccessor() or TRedoSuccessor() or TRetrySuccessor() @@ -357,13 +359,14 @@ class ExitSuccessor extends AbruptSuccessorImpl, TExitSuccessor { } private class TJumpSuccessor = - TBreakSuccessor or TContinueSuccessor or TGotoSuccessor or TRedoSuccessor or TRetrySuccessor; + TBreakSuccessor or TContinueSuccessor or TFallthroughSuccessor or TGotoSuccessor or + TRedoSuccessor or TRetrySuccessor; /** * A jump control flow successor. * * This covers non-exceptional, non-local control flow, such as `break`, - * `continue`, and `goto`. + * `continue`, `fallthrough`, and `goto`. */ abstract private class JumpSuccessorImpl extends AbruptSuccessorImpl, TJumpSuccessor { } @@ -379,6 +382,11 @@ class ContinueSuccessor extends JumpSuccessorImpl, TContinueSuccessor { override string toString() { result = "continue" } } +/** A `fallthrough` control flow successor. */ +class FallthroughSuccessor extends JumpSuccessorImpl, TFallthroughSuccessor { + override string toString() { result = "fallthrough" } +} + /** A `goto` control flow successor. */ class GotoSuccessor extends JumpSuccessorImpl, TGotoSuccessor { override string toString() { result = "goto" } From 5ce29b02d30d95acef5d5eabf9a6afe2af899f4b Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 14:19:30 +0100 Subject: [PATCH 5/8] Unified: Swift `fallthrough` uses shared CFG fallthrough implementation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- .../unified/internal/ControlFlowGraph.qll | 2 ++ .../controlflow/basicblock-slices.expected | 15 +++++----- .../library-tests/controlflow/cfg.expected | 25 +++++++++-------- .../test/library-tests/controlflow/cfg.swift | 4 +-- .../controlflow/fallthrough.swift | 28 +++++++++---------- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll index 26a08e1df71f..165cf5300c2c 100644 --- a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll +++ b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll @@ -192,6 +192,8 @@ module Ast implements AstSig { class ContinueStmt = U::ContinueExpr; + class FallthroughStmt = U::FallthroughStmt; + class LabeledStmt = U::LabeledStmt; class GotoStmt extends Stmt { diff --git a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected index 064c47837ba3..1926e2839a61 100644 --- a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected +++ b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected @@ -9,8 +9,7 @@ | 4 | fallthrough.swift:4:13:7:5 | Block | 'Block' | | 5 | cfg.swift:5:1:5:37 | func returnZero | 'func returnZero -V returnZero' | | 5 | cfg.swift:5:26:5:37 | Block | 'Block -V 0 -^ ReturnExpr' | -| 5 | fallthrough.swift:5:7:5:17 | | '' | -| 6 | fallthrough.swift:6:7:6:11 | print | 'print -> Argument -V "unreachable" -^ print(...)' | +| 5 | fallthrough.swift:5:7:5:17 | fallthrough | 'fallthrough' | | 7 | cfg.swift:7:1:7:10 | returnZero | 'returnZero -^ returnZero(...)' | | 8 | cfg.swift:8:1:8:6 | Double | 'Double -> Argument -V topLevelDecl -^ Double(...)' | | 8 | fallthrough.swift:8:5:8:9 | print | 'print -> Argument -V "stay in first case" -^ print(...)' | @@ -21,12 +20,12 @@ | 11 | fallthrough.swift:11:5:12:15 | Block | 'Block -V print -> Argument -V "second case" -^ print(...)' | | 12 | cfg.swift:12:10:12:31 | MyError.error3 | 'MyError.error3 -V error3 -^ MyError.error3.(constructor)' | | 12 | cfg.swift:12:17:12:25 | withParam | 'withParam -? Block' | -| 12 | fallthrough.swift:12:5:12:15 | | '' | +| 12 | fallthrough.swift:12:5:12:15 | fallthrough | 'fallthrough' | | 13 | fallthrough.swift:13:3:15:15 | SwitchCase | 'SwitchCase -V 2' | | 14 | fallthrough.swift:14:5:15:15 | Block | 'Block -V print -> Argument -V "third case" -^ print(...)' | | 15 | cfg.swift:15:1:17:1 | func isZero | 'func isZero -V isZero' | | 15 | cfg.swift:15:13:15:13 | x | 'x -> Block' | -| 15 | fallthrough.swift:15:5:15:15 | | '' | +| 15 | fallthrough.swift:15:5:15:15 | fallthrough | 'fallthrough' | | 16 | cfg.swift:16:10:16:10 | x | 'x -> 0 -^ ... == ... -^ ReturnExpr' | | 16 | fallthrough.swift:16:3:17:25 | SwitchCase | 'SwitchCase' | | 17 | fallthrough.swift:17:5:17:25 | Block | 'Block -V print -> Argument -V "default case" -^ print(...)' | @@ -45,7 +44,7 @@ | 24 | fallthrough.swift:24:3:32:15 | SwitchCase | 'SwitchCase -V 0' | | 25 | fallthrough.swift:25:5:32:15 | Block | 'Block -V SwitchExpr -V y' | | 26 | fallthrough.swift:26:5:27:17 | SwitchCase | 'SwitchCase -V 0' | -| 27 | fallthrough.swift:27:7:27:17 | Block | 'Block -V ' | +| 27 | fallthrough.swift:27:7:27:17 | Block | 'Block -V fallthrough' | | 28 | cfg.swift:28:1:45:1 | func tryCatch | 'func tryCatch -V tryCatch' | | 28 | cfg.swift:28:15:28:15 | x | 'x -> Block' | | 28 | fallthrough.swift:28:5:29:28 | SwitchCase | 'SwitchCase' | @@ -56,7 +55,7 @@ | 31 | cfg.swift:31:5:31:9 | print | 'print -> Argument -V "Did not throw." -^ print(...)' | | 31 | fallthrough.swift:31:5:31:9 | print | 'print -> Argument -V "after inner switch" -^ print(...)' | | 32 | cfg.swift:32:10:32:19 | mightThrow | 'mightThrow -> Argument -V 0 -^ mightThrow(...) -^ try! ...' | -| 32 | fallthrough.swift:32:5:32:15 | | '' | +| 32 | fallthrough.swift:32:5:32:15 | fallthrough | 'fallthrough' | | 33 | cfg.swift:33:5:33:9 | print | 'print -> Argument -V "Still did not throw." -^ print(...)' | | 33 | fallthrough.swift:33:3:34:26 | SwitchCase | 'SwitchCase' | | 34 | fallthrough.swift:34:5:34:26 | Block | 'Block -V print -> Argument -V "outer default" -^ print(...)' | @@ -88,7 +87,7 @@ | 47 | fallthrough.swift:47:9:47:13 | print | 'print -> Argument -V "inner defer" -^ print(...)' | | 48 | cfg.swift:48:10:50:3 | FunctionExpr | 'FunctionExpr -^ ReturnExpr' | | 49 | cfg.swift:49:5:49:17 | Block | 'Block -V s -> "" -^ ... + ... -^ ReturnExpr' | -| 49 | fallthrough.swift:49:7:49:17 | | '' | +| 49 | fallthrough.swift:49:7:49:17 | fallthrough | 'fallthrough' | | 51 | fallthrough.swift:51:3:52:22 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' | | 52 | fallthrough.swift:52:5:52:22 | Block | 'Block -V print -> Argument -V "next case" -^ print(...)' | | 53 | cfg.swift:53:1:58:1 | func createClosure2 | 'func createClosure2 -V createClosure2' | @@ -181,7 +180,7 @@ | 154 | cfg.swift:154:7:154:17 | Block | 'Block -V true -^ ReturnExpr' | | 155 | cfg.swift:155:5:157:17 | SwitchCase | 'SwitchCase -V 42' | | 156 | cfg.swift:156:7:157:17 | Block | 'Block -V print -> Argument -V "42!" -^ print(...)' | -| 157 | cfg.swift:157:7:157:17 | | '' | +| 157 | cfg.swift:157:7:157:17 | fallthrough | 'fallthrough' | | 158 | cfg.swift:158:5:159:34 | SwitchCase | 'SwitchCase' | | 159 | cfg.swift:159:7:159:34 | Block | 'Block -V IfExpr -V x -> 10 -^ ... > ...' | | 159 | cfg.swift:159:19:159:34 | Block | 'Block -V false -^ ReturnExpr' | diff --git a/unified/ql/test/library-tests/controlflow/cfg.expected b/unified/ql/test/library-tests/controlflow/cfg.expected index 59cc374a8a0e..b1cf19c84a27 100644 --- a/unified/ql/test/library-tests/controlflow/cfg.expected +++ b/unified/ql/test/library-tests/controlflow/cfg.expected @@ -4,9 +4,9 @@ bbContinues | cfg.swift:184:5:184:14 | print(...) | 'print(...) goto Block(-7)' | | cfg.swift:190:7:190:16 | print(...) | 'print(...) goto Block(-7)' | | fallthrough.swift:42:5:42:5 | DeferStmt | 'DeferStmt goto TryExpr(+3)' | -| fallthrough.swift:46:7:46:7 | DeferStmt | 'DeferStmt goto (+3)' | +| fallthrough.swift:46:7:46:7 | DeferStmt | 'DeferStmt goto fallthrough(+3)' | | fallthrough.swift:47:9:47:28 | print(...) | 'print(...) goto Block(-5)' | -| fallthrough.swift:49:7:49:17 | | ' goto Block(-3)' | +| fallthrough.swift:49:7:49:17 | fallthrough | 'fallthrough goto Block(-3)' | bbStep | cfg.swift:20:9:20:14 | ... >= ... | '... >= ... : false -> Block(+0)' | | cfg.swift:20:9:20:14 | ... >= ... | '... >= ... : true -> GuardIfStmt(+3)' | @@ -42,7 +42,8 @@ bbStep | cfg.swift:153:13:153:17 | ... < ... | '... < ... : successor -> x(-2)' | | cfg.swift:155:10:155:11 | 42 | '42 : match -> Block(+1)' | | cfg.swift:155:10:155:11 | 42 | '42 : no-match -> SwitchCase(+3)' | -| cfg.swift:157:7:157:17 | | ' : successor -> var obj(+5)' | +| cfg.swift:157:7:157:17 | fallthrough | 'fallthrough : fallthrough -> Block(+2)' | +| cfg.swift:158:5:158:5 | SwitchCase | 'SwitchCase : successor -> Block(+1)' | | cfg.swift:159:11:159:16 | ... > ... | '... > ... : false -> var obj(+3)' | | cfg.swift:159:11:159:16 | ... > ... | '... > ... : true -> Block(+0)' | | cfg.swift:163:6:163:13 | TypeTestExpr | 'TypeTestExpr : false -> let xOptional(+4)' | @@ -175,26 +176,27 @@ bbStep | fallthrough.swift:3:8:3:8 | 0 | '0 : no-match -> SwitchCase(+7)' | | fallthrough.swift:4:8:4:11 | flag | 'flag : false -> print(+4)' | | fallthrough.swift:4:8:4:11 | flag | 'flag : true -> Block(+0)' | -| fallthrough.swift:6:7:6:26 | print(...) | 'print(...) : successor -> print(+2)' | +| fallthrough.swift:5:7:5:17 | fallthrough | 'fallthrough : fallthrough -> Block(+6)' | | fallthrough.swift:9:5:9:9 | BreakExpr | 'BreakExpr : break -> print(+10)' | | fallthrough.swift:10:8:10:19 | ConditionalPattern | 'ConditionalPattern : match -> Block(+1)' | | fallthrough.swift:10:8:10:19 | ConditionalPattern | 'ConditionalPattern : no-match -> SwitchCase(+3)' | -| fallthrough.swift:12:5:12:15 | | ' : successor -> print(+7)' | +| fallthrough.swift:12:5:12:15 | fallthrough | 'fallthrough : fallthrough -> Block(+2)' | | fallthrough.swift:13:8:13:8 | 2 | '2 : match -> Block(+1)' | | fallthrough.swift:13:8:13:8 | 2 | '2 : no-match -> SwitchCase(+3)' | -| fallthrough.swift:15:5:15:15 | | ' : successor -> print(+4)' | +| fallthrough.swift:15:5:15:15 | fallthrough | 'fallthrough : fallthrough -> Block(+2)' | +| fallthrough.swift:16:3:16:3 | SwitchCase | 'SwitchCase : successor -> Block(+1)' | | fallthrough.swift:17:5:17:25 | print(...) | 'print(...) : successor -> print(+2)' | | fallthrough.swift:24:8:24:8 | 0 | '0 : match -> Block(+1)' | | fallthrough.swift:24:8:24:8 | 0 | '0 : no-match -> SwitchCase(+9)' | | fallthrough.swift:26:10:26:10 | 0 | '0 : match -> Block(+1)' | | fallthrough.swift:26:10:26:10 | 0 | '0 : no-match -> SwitchCase(+2)' | -| fallthrough.swift:27:7:27:17 | | ' : successor -> print(+4)' | -| fallthrough.swift:29:7:29:28 | print(...) | 'print(...) : successor -> print(+2)' | -| fallthrough.swift:32:5:32:15 | | ' : successor -> print(+4)' | -| fallthrough.swift:34:5:34:26 | print(...) | 'print(...) : successor -> print(+2)' | +| fallthrough.swift:27:7:27:17 | fallthrough | 'fallthrough : fallthrough -> Block(+2)' | +| fallthrough.swift:28:5:28:5 | SwitchCase | 'SwitchCase : successor -> Block(+1)' | +| fallthrough.swift:32:5:32:15 | fallthrough | 'fallthrough : fallthrough -> Block(+2)' | +| fallthrough.swift:33:3:33:3 | SwitchCase | 'SwitchCase : successor -> Block(+1)' | | fallthrough.swift:41:8:41:8 | 0 | '0 : match -> Block(+1)' | | fallthrough.swift:41:8:41:8 | 0 | '0 : no-match -> SwitchCase(+10)' | -| fallthrough.swift:43:7:43:26 | print(...) | 'print(...) : successor -> print(+13)' | +| fallthrough.swift:43:7:43:26 | print(...) | 'print(...) : fallthrough -> Block(+9)' | | fallthrough.swift:51:8:51:19 | ConditionalPattern | 'ConditionalPattern : match -> Block(+1)' | | fallthrough.swift:51:8:51:19 | ConditionalPattern | 'ConditionalPattern : no-match -> SwitchCase(+2)' | | fallthrough.swift:52:5:52:22 | print(...) | 'print(...) : successor -> print(+4)' | @@ -220,6 +222,7 @@ noCfg | cfg.swift:564:49:564:51 | Int | | cfg.swift:622:3:622:11 | ReturnExpr | | cfg.swift:634:3:634:11 | ReturnExpr | +| fallthrough.swift:6:7:6:11 | print | nonSimple | cfg.swift:12:17:12:25 | withParam | 'withParam -? Block' | | cfg.swift:35:5:35:5 | CatchClause | 'CatchClause -V MyError -^ ... .error1 -> isZero -> Argument -V x -^ isZero(...) -? MyError -^ ... .error2 -^ ConditionalPattern -^ OrPattern' | diff --git a/unified/ql/test/library-tests/controlflow/cfg.swift b/unified/ql/test/library-tests/controlflow/cfg.swift index 249832270920..c239336a508f 100644 --- a/unified/ql/test/library-tests/controlflow/cfg.swift +++ b/unified/ql/test/library-tests/controlflow/cfg.swift @@ -154,8 +154,8 @@ func patterns(x : Int) -> Bool { return true case 42: // $ bbStep='42 : match -> Block(+1)' bbStep='42 : no-match -> SwitchCase(+3)' print("42!") - fallthrough // $ bbStep=' : successor -> var obj(+5)' - default: + fallthrough // $ bbStep='fallthrough : fallthrough -> Block(+2)' + default: // $ bbStep='SwitchCase : successor -> Block(+1)' if (x > 10) { return false } // $ bbStep='... > ... : false -> var obj(+3)' bbStep='... > ... : true -> Block(+0)' } diff --git a/unified/ql/test/library-tests/controlflow/fallthrough.swift b/unified/ql/test/library-tests/controlflow/fallthrough.swift index f96ceb3f0ec4..ca12cc746c62 100644 --- a/unified/ql/test/library-tests/controlflow/fallthrough.swift +++ b/unified/ql/test/library-tests/controlflow/fallthrough.swift @@ -2,18 +2,18 @@ func fallthroughChain(_ x: Int, _ flag: Bool) { switch x { case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+7)' if flag { // $ bbStep='flag : false -> print(+4)' bbStep='flag : true -> Block(+0)' - fallthrough - print("unreachable") // $ bbStep='print(...) : successor -> print(+2)' + fallthrough // $ bbStep='fallthrough : fallthrough -> Block(+6)' + print("unreachable") // $ noCfg } print("stay in first case") break // $ bbStep='BreakExpr : break -> print(+10)' case 1 where flag: // $ bbStep='ConditionalPattern : match -> Block(+1)' bbStep='ConditionalPattern : no-match -> SwitchCase(+3)' nonSimple='SwitchCase -V flag -? 1 -^ ConditionalPattern' print("second case") - fallthrough // $ bbStep=' : successor -> print(+7)' + fallthrough // $ bbStep='fallthrough : fallthrough -> Block(+2)' case 2: // $ bbStep='2 : match -> Block(+1)' bbStep='2 : no-match -> SwitchCase(+3)' print("third case") - fallthrough // $ bbStep=' : successor -> print(+4)' - default: + fallthrough // $ bbStep='fallthrough : fallthrough -> Block(+2)' + default: // $ bbStep='SwitchCase : successor -> Block(+1)' print("default case") // $ bbStep='print(...) : successor -> print(+2)' } print("after switch") @@ -24,14 +24,14 @@ func nestedFallthrough(_ x: Int, _ y: Int) { case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+9)' switch y { case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+2)' - fallthrough // $ bbStep=' : successor -> print(+4)' - default: - print("inner default") // $ bbStep='print(...) : successor -> print(+2)' + fallthrough // $ bbStep='fallthrough : fallthrough -> Block(+2)' + default: // $ bbStep='SwitchCase : successor -> Block(+1)' + print("inner default") } print("after inner switch") - fallthrough // $ bbStep=' : successor -> print(+4)' - default: - print("outer default") // $ bbStep='print(...) : successor -> print(+2)' + fallthrough // $ bbStep='fallthrough : fallthrough -> Block(+2)' + default: // $ bbStep='SwitchCase : successor -> Block(+1)' + print("outer default") } print("after outer switch") } @@ -40,13 +40,13 @@ func fallthroughWithDefer(_ x: Int, _ flag: Bool) { switch x { case 0: // $ bbStep='0 : match -> Block(+1)' bbStep='0 : no-match -> SwitchCase(+10)' defer { // $ bbContinues='DeferStmt goto TryExpr(+3)' - print("outer defer") // $ bbStep='print(...) : successor -> print(+13)' + print("outer defer") // $ bbStep='print(...) : fallthrough -> Block(+9)' } do { - defer { // $ bbContinues='DeferStmt goto (+3)' + defer { // $ bbContinues='DeferStmt goto fallthrough(+3)' print("inner defer") // $ bbContinues='print(...) goto Block(-5)' } - fallthrough // $ bbContinues=' goto Block(-3)' + fallthrough // $ bbContinues='fallthrough goto Block(-3)' } case 1 where flag: // $ bbStep='ConditionalPattern : match -> Block(+1)' bbStep='ConditionalPattern : no-match -> SwitchCase(+2)' nonSimple='SwitchCase -V flag -? 1 -^ ConditionalPattern' print("next case") // $ bbStep='print(...) : successor -> print(+4)' From 08d5979861691c2664e019a7d94a8face45ec6f0 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 14:20:10 +0100 Subject: [PATCH 6/8] Go: Use shared `fallthrough` CFG support Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll | 9 +++------ .../ControlFlowNode_getASuccessor.expected | 9 ++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll index 9d73c09a2a75..40eb471a6cfb 100644 --- a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -256,6 +256,8 @@ module CfgImpl { class ContinueStmt = Go::ContinueStmt; + class FallthroughStmt = Go::FallthroughStmt; + class GotoStmt = Go::GotoStmt; class ReturnStmt = Go::ReturnStmt; @@ -324,12 +326,7 @@ module CfgImpl { AstNode getSwitchInit(Switch switch) { result = switch.(Go::SwitchStmt).getInit() } - predicate fallsThrough(Case c) { - // Go has no implicit fall-through between case clauses; an explicit - // `fallthrough` statement is required. - c.(Go::CaseClause).getStmt(max(int i | exists(c.(Go::CaseClause).getStmt(i)))) instanceof - Go::FallthroughStmt - } + predicate fallsThrough(Case c) { none() } /** * Holds if `s` is the flattened body element at position (`caseIdx`, diff --git a/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected b/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected index 63583896a9f7..6c80c1a9b99e 100644 --- a/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected +++ b/go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected @@ -1208,13 +1208,14 @@ | fallthrough.go:4:2:10:2 | After expression-switch statement | fallthrough.go:11:2:11:13 | expression statement | | fallthrough.go:4:2:10:2 | expression-switch statement | fallthrough.go:4:9:4:9 | x | | fallthrough.go:4:9:4:9 | x | fallthrough.go:5:2:6:13 | case clause | -| fallthrough.go:5:2:6:13 | After case clause [match] | fallthrough.go:6:3:6:13 | fallthrough statement | +| fallthrough.go:5:2:6:13 | After case clause [match] | fallthrough.go:6:3:6:13 | Before fallthrough statement | | fallthrough.go:5:2:6:13 | After case clause [no-match] | fallthrough.go:7:2:7:8 | case clause | | fallthrough.go:5:2:6:13 | case clause | fallthrough.go:5:7:5:7 | 0 | | fallthrough.go:5:7:5:7 | 0 | fallthrough.go:5:7:5:7 | After 0 [match] | | fallthrough.go:5:7:5:7 | 0 | fallthrough.go:5:7:5:7 | After 0 [no-match] | | fallthrough.go:5:7:5:7 | After 0 [match] | fallthrough.go:5:2:6:13 | After case clause [match] | | fallthrough.go:5:7:5:7 | After 0 [no-match] | fallthrough.go:5:2:6:13 | After case clause [no-match] | +| fallthrough.go:6:3:6:13 | Before fallthrough statement | fallthrough.go:6:3:6:13 | fallthrough statement | | fallthrough.go:6:3:6:13 | fallthrough statement | fallthrough.go:4:2:10:2 | After expression-switch statement | | fallthrough.go:7:2:7:8 | After case clause [match] | fallthrough.go:4:2:10:2 | After expression-switch statement | | fallthrough.go:7:2:7:8 | After case clause [no-match] | fallthrough.go:8:2:9:13 | case clause | @@ -1251,13 +1252,14 @@ | fallthrough.go:15:2:19:2 | After expression-switch statement | fallthrough.go:20:2:20:13 | expression statement | | fallthrough.go:15:2:19:2 | expression-switch statement | fallthrough.go:15:9:15:9 | x | | fallthrough.go:15:9:15:9 | x | fallthrough.go:16:2:17:13 | case clause | -| fallthrough.go:16:2:17:13 | After case clause [match] | fallthrough.go:17:3:17:13 | fallthrough statement | +| fallthrough.go:16:2:17:13 | After case clause [match] | fallthrough.go:17:3:17:13 | Before fallthrough statement | | fallthrough.go:16:2:17:13 | After case clause [no-match] | fallthrough.go:18:2:18:9 | case clause | | fallthrough.go:16:2:17:13 | case clause | fallthrough.go:16:7:16:7 | 0 | | fallthrough.go:16:7:16:7 | 0 | fallthrough.go:16:7:16:7 | After 0 [match] | | fallthrough.go:16:7:16:7 | 0 | fallthrough.go:16:7:16:7 | After 0 [no-match] | | fallthrough.go:16:7:16:7 | After 0 [match] | fallthrough.go:16:2:17:13 | After case clause [match] | | fallthrough.go:16:7:16:7 | After 0 [no-match] | fallthrough.go:16:2:17:13 | After case clause [no-match] | +| fallthrough.go:17:3:17:13 | Before fallthrough statement | fallthrough.go:17:3:17:13 | fallthrough statement | | fallthrough.go:17:3:17:13 | fallthrough statement | fallthrough.go:15:2:19:2 | After expression-switch statement | | fallthrough.go:18:2:18:9 | After case clause [match] | fallthrough.go:15:2:19:2 | After expression-switch statement | | fallthrough.go:18:2:18:9 | case clause | fallthrough.go:18:2:18:9 | After case clause [match] | @@ -3004,12 +3006,13 @@ | stmts.go:91:7:91:7 | After 1 [no-match] | stmts.go:91:2:93:13 | After case clause [no-match] | | stmts.go:92:3:92:7 | test5 | stmts.go:92:9:92:13 | false | | stmts.go:92:3:92:14 | After call to test5 | stmts.go:92:3:92:14 | After expression statement | -| stmts.go:92:3:92:14 | After expression statement | stmts.go:93:3:93:13 | fallthrough statement | +| stmts.go:92:3:92:14 | After expression statement | stmts.go:93:3:93:13 | Before fallthrough statement | | stmts.go:92:3:92:14 | Before call to test5 | stmts.go:92:3:92:7 | test5 | | stmts.go:92:3:92:14 | call to test5 | stmts.go:75:1:109:1 | Exceptional Exit | | stmts.go:92:3:92:14 | call to test5 | stmts.go:92:3:92:14 | After call to test5 | | stmts.go:92:3:92:14 | expression statement | stmts.go:92:3:92:14 | Before call to test5 | | stmts.go:92:9:92:13 | false | stmts.go:92:3:92:14 | call to test5 | +| stmts.go:93:3:93:13 | Before fallthrough statement | stmts.go:93:3:93:13 | fallthrough statement | | stmts.go:93:3:93:13 | fallthrough statement | stmts.go:95:3:95:13 | expression statement | | stmts.go:94:2:95:13 | After case clause [match] | stmts.go:95:3:95:13 | expression statement | | stmts.go:94:2:95:13 | After case clause [no-match] | stmts.go:90:2:96:2 | After expression-switch statement | From 4d3624c5a069ce3d191340748d7349bfb8e10f46 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 14:20:12 +0100 Subject: [PATCH 7/8] Ruby, C#, Java, Python, Actions: Update CFG library instantiations Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23fe5d28-31ea-484f-aa0e-82adaedaf057 --- actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll | 4 ++++ .../code/csharp/controlflow/internal/ControlFlowGraph.qll | 4 ++++ java/ql/lib/semmle/code/java/ControlFlowGraph.qll | 4 ++++ .../lib/semmle/python/controlflow/internal/AstNodeImpl.qll | 5 +++++ ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll b/actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll index f01fdbd0e4a1..b3635e0437f8 100644 --- a/actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll +++ b/actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll @@ -204,6 +204,10 @@ module CfgImpl { ContinueStmt() { none() } } + class FallthroughStmt extends Stmt { + FallthroughStmt() { none() } + } + class GotoStmt extends Stmt { GotoStmt() { none() } } diff --git a/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll b/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll index 60051b7e6c3c..254fad1579aa 100644 --- a/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll +++ b/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll @@ -204,6 +204,10 @@ module Ast implements AstSig { class ContinueStmt = CS::ContinueStmt; + class FallthroughStmt extends Stmt { + FallthroughStmt() { none() } + } + class GotoStmt = CS::GotoStmt; class ReturnStmt = CS::ReturnStmt; diff --git a/java/ql/lib/semmle/code/java/ControlFlowGraph.qll b/java/ql/lib/semmle/code/java/ControlFlowGraph.qll index b7fb06876905..d8cdfe63ae84 100644 --- a/java/ql/lib/semmle/code/java/ControlFlowGraph.qll +++ b/java/ql/lib/semmle/code/java/ControlFlowGraph.qll @@ -114,6 +114,10 @@ private module Ast implements AstSig { class ContinueStmt = J::ContinueStmt; + class FallthroughStmt extends Stmt { + FallthroughStmt() { none() } + } + class GotoStmt extends Stmt { GotoStmt() { none() } } diff --git a/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll b/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll index 802cf2cf79f0..8bec9f2a229b 100644 --- a/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll +++ b/python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll @@ -700,6 +700,11 @@ module Ast implements AstSig { ContinueStmt() { this = TPyStmt(any(Py::Continue c)) } } + /** A `fallthrough` statement. Python has no fallthrough. */ + class FallthroughStmt extends Stmt { + FallthroughStmt() { none() } + } + /** A `goto` statement. Python has no goto. */ class GotoStmt extends Stmt { GotoStmt() { none() } diff --git a/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll b/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll index 8f0ecd549991..74923a307b43 100644 --- a/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll +++ b/ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph.qll @@ -308,6 +308,10 @@ private module Ast implements AstSig { class ContinueStmt extends Stmt instanceof R::Ast::NextStmt { } + class FallthroughStmt extends Stmt { + FallthroughStmt() { none() } + } + class LabeledStmt extends Stmt { LabeledStmt() { none() } From f79c3fe31a9acfcdae6e8f781c0cf4001275342d Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 17 Nov 2026 15:44:21 +0100 Subject: [PATCH 8/8] Unified: Remove `fallThroughStmt` from unsupported nodes --- unified/extractor/src/languages/swift/swift.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index dfa74833ee6c..2fbe8ef20f1f 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -1636,7 +1636,6 @@ fn translation_rules() -> Vec> { rule!((classRestrictionType) => (unsupported_node "")), rule!((compositionType) => (unsupported_node "")), rule!((discardStmt) => (unsupported_node "")), - rule!((fallThroughStmt) => (unsupported_node "")), rule!((implicitlyUnwrappedOptionalType) => (unsupported_node "")), rule!((inlineArrayType) => (unsupported_node "")), rule!((keyPathExpr) => (unsupported_node "")),