Skip to content

Commit 07e450d

Browse files
authored
Merge pull request #9269 from igfoo/igfoo/cfg
Kotlin: Fix CFG
2 parents fd60ab4 + 8e64978 commit 07e450d

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private module ControlFlowGraphImpl {
286286
* That is, contexts where the control-flow edges depend on `value` given that `b` ends
287287
* with a `booleanCompletion(value, _)`.
288288
*/
289-
private predicate inBooleanContext(Expr b) {
289+
private predicate inBooleanContext(ControlFlowNode b) {
290290
exists(LogicExpr logexpr |
291291
logexpr.(BinaryExpr).getLeftOperand() = b
292292
or
@@ -316,6 +316,10 @@ private module ControlFlowGraphImpl {
316316
inBooleanContext(whenexpr) and
317317
whenexpr.getBranch(_).getAResult() = b
318318
)
319+
or
320+
inBooleanContext(b.(ExprStmt).getExpr())
321+
or
322+
inBooleanContext(b.(StmtExpr).getStmt())
319323
}
320324

321325
/**
@@ -907,7 +911,8 @@ private module ControlFlowGraphImpl {
907911
)
908912
or
909913
// the last node in an `ExprStmt` is the last node in the expression
910-
last(n.(ExprStmt).getExpr(), last, completion) and completion = NormalCompletion()
914+
last(n.(ExprStmt).getExpr(), last, completion) and
915+
completion instanceof NormalOrBooleanCompletion
911916
or
912917
// the last node in a `StmtExpr` is the last node in the statement
913918
last(n.(StmtExpr).getStmt(), last, completion)

java/ql/test/kotlin/library-tests/controlflow/basic/bbStrictDominance.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@
5353
| Test.kt:118:37:124:1 | { ... } | Test.kt:121:9:121:9 | <Expr>; |
5454
| Test.kt:118:37:124:1 | { ... } | Test.kt:122:12:122:16 | ... -> ... |
5555
| Test.kt:118:37:124:1 | { ... } | Test.kt:123:8:123:10 | { ... } |
56-
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:118:1:124:1 | fn_when |
5756
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:123:8:123:10 | { ... } |

java/ql/test/kotlin/library-tests/controlflow/basic/bbSuccessor.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@
4141
| Test.kt:118:37:124:1 | { ... } | Test.kt:122:12:122:16 | ... -> ... |
4242
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:118:1:124:1 | fn_when |
4343
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:123:8:123:10 | { ... } |
44+
| Test.kt:122:12:122:16 | ... -> ... | Test.kt:118:1:124:1 | fn_when |
4445
| Test.kt:123:8:123:10 | { ... } | Test.kt:118:1:124:1 | fn_when |

java/ql/test/kotlin/library-tests/controlflow/basic/getASuccessor.expected

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
missingSuccessor
2-
| Test.kt:122:12:122:16 | false |
32
#select
43
| Test.kt:0:0:0:0 | TestKt | Class | file://:0:0:0:0 | <none> | <none> |
54
| Test.kt:3:1:80:1 | Test | Class | file://:0:0:0:0 | <none> | <none> |
@@ -257,6 +256,6 @@ missingSuccessor
257256
| Test.kt:121:9:121:9 | y | VarAccess | Test.kt:123:8:123:10 | { ... } | BlockStmt |
258257
| Test.kt:122:12:122:16 | ... -> ... | WhenBranch | Test.kt:122:12:122:16 | true | BooleanLiteral |
259258
| Test.kt:122:12:122:16 | <Expr>; | ExprStmt | Test.kt:122:12:122:16 | false | BooleanLiteral |
260-
| Test.kt:122:12:122:16 | false | BooleanLiteral | file://:0:0:0:0 | <none> | <none> |
259+
| Test.kt:122:12:122:16 | false | BooleanLiteral | Test.kt:118:1:124:1 | fn_when | Method |
261260
| Test.kt:122:12:122:16 | true | BooleanLiteral | Test.kt:122:12:122:16 | <Expr>; | ExprStmt |
262261
| Test.kt:123:8:123:10 | { ... } | BlockStmt | Test.kt:118:1:124:1 | fn_when | Method |

java/ql/test/kotlin/library-tests/controlflow/basic/strictPostDominance.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,4 @@
220220
| Test.kt:121:4:121:9 | ... -> ... | Test.kt:118:37:124:1 | { ... } |
221221
| Test.kt:121:4:121:9 | ... -> ... | Test.kt:119:2:123:12 | <Expr>; |
222222
| Test.kt:121:4:121:9 | ... -> ... | Test.kt:120:3:123:10 | ... -> ... |
223-
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:118:37:124:1 | { ... } |
224-
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:119:2:123:12 | <Expr>; |
225-
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:120:3:123:10 | ... -> ... |
226-
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:121:4:121:9 | ... -> ... |
227223
| Test.kt:122:12:122:16 | <Expr>; | Test.kt:122:12:122:16 | ... -> ... |

0 commit comments

Comments
 (0)