Skip to content

Commit 2782d90

Browse files
authored
Merge pull request #21403 from aschackmull/cfg/tweaks
Cfg: Small tweaks.
2 parents 6a904ed + daefd59 commit 2782d90

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

java/ql/test/library-tests/guards12/guard.expected

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ hasBranchEdge
1111
| Test.java:11:7:11:17 | case ... | Test.java:11:7:11:17 | case ... | Test.java:12:7:12:17 | case ... | false |
1212
| Test.java:12:7:12:17 | case ... | Test.java:12:7:12:17 | case ... | Test.java:12:12:12:14 | "d" | true |
1313
| Test.java:12:7:12:17 | case ... | Test.java:12:7:12:17 | case ... | Test.java:13:7:13:16 | default | false |
14+
| Test.java:17:7:17:36 | case <Pattern> | Test.java:15:5:15:25 | var ...; | Test.java:17:7:17:36 | After case <Pattern> [no-match] | false |
1415
| Test.java:17:7:17:36 | case <Pattern> | Test.java:15:5:15:25 | var ...; | Test.java:17:19:17:19 | <anonymous local variable> | true |
15-
| Test.java:17:7:17:36 | case <Pattern> | Test.java:15:5:15:25 | var ...; | Test.java:18:7:18:17 | case ... | false |
1616
| Test.java:17:26:17:33 | ... == ... | Test.java:17:19:17:19 | <anonymous local variable> | Test.java:17:26:17:33 | After ... == ... [false] | false |
1717
| Test.java:17:26:17:33 | ... == ... | Test.java:17:19:17:19 | <anonymous local variable> | Test.java:17:38:17:40 | { ... } | true |
1818
| Test.java:18:7:18:17 | case ... | Test.java:18:7:18:17 | case ... | Test.java:18:12:18:14 | "e" | true |
@@ -21,16 +21,16 @@ hasBranchEdge
2121
| Test.java:21:13:21:19 | unknown | Test.java:21:5:21:42 | switch (...) | Test.java:21:27:21:27 | s | false |
2222
| Test.java:22:7:22:17 | case ... | Test.java:22:7:22:17 | case ... | Test.java:22:12:22:14 | "f" | true |
2323
| Test.java:22:7:22:17 | case ... | Test.java:22:7:22:17 | case ... | Test.java:23:7:23:37 | case <Pattern> | false |
24+
| Test.java:23:7:23:37 | case <Pattern> | Test.java:23:7:23:37 | case <Pattern> | Test.java:23:7:23:37 | After case <Pattern> [no-match] | false |
2425
| Test.java:23:7:23:37 | case <Pattern> | Test.java:23:7:23:37 | case <Pattern> | Test.java:23:19:23:20 | s2 | true |
25-
| Test.java:23:7:23:37 | case <Pattern> | Test.java:23:7:23:37 | case <Pattern> | Test.java:24:7:24:17 | case ... | false |
2626
| Test.java:23:27:23:34 | ... == ... | Test.java:23:19:23:20 | s2 | Test.java:23:27:23:34 | After ... == ... [false] | false |
2727
| Test.java:23:27:23:34 | ... == ... | Test.java:23:19:23:20 | s2 | Test.java:23:39:23:41 | { ... } | true |
2828
| Test.java:24:7:24:17 | case ... | Test.java:24:7:24:17 | case ... | Test.java:24:12:24:14 | "g" | true |
2929
| Test.java:24:7:24:17 | case ... | Test.java:24:7:24:17 | case ... | Test.java:25:7:25:16 | default | false |
3030
| Test.java:28:7:28:15 | case ... | Test.java:27:5:27:14 | switch (...) | Test.java:28:12:28:14 | "h" | true |
3131
| Test.java:28:7:28:15 | case ... | Test.java:27:5:27:14 | switch (...) | Test.java:29:7:29:34 | case <Pattern> | false |
32+
| Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | After case <Pattern> [no-match] | false |
3233
| Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | case <Pattern> | Test.java:29:19:29:19 | <anonymous local variable> | true |
33-
| Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | case <Pattern> | Test.java:30:7:30:15 | case ... | false |
3434
| Test.java:29:26:29:33 | ... == ... | Test.java:29:19:29:19 | <anonymous local variable> | Test.java:29:26:29:33 | After ... == ... [false] | false |
3535
| Test.java:29:26:29:33 | ... == ... | Test.java:29:19:29:19 | <anonymous local variable> | Test.java:29:26:29:33 | After ... == ... [true] | true |
3636
| Test.java:30:7:30:15 | case ... | Test.java:30:7:30:15 | case ... | Test.java:30:12:30:14 | "i" | true |
@@ -52,6 +52,7 @@ hasBranchEdge
5252
| Test.java:17:26:17:33 | ... == ... | Test.java:17:26:17:28 | len | Test.java:17:33:17:33 | 4 | true | true | Test.java:17:38:17:40 | { ... } |
5353
| Test.java:18:7:18:17 | case ... | Test.java:16:13:16:13 | s | Test.java:18:12:18:14 | "e" | true | false | Test.java:19:7:19:16 | default |
5454
| Test.java:18:7:18:17 | case ... | Test.java:16:13:16:13 | s | Test.java:18:12:18:14 | "e" | true | true | Test.java:18:12:18:14 | "e" |
55+
| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:7:23:37 | After case <Pattern> [no-match] |
5556
| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:7:23:37 | case <Pattern> |
5657
| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:19:23:20 | s2 |
5758
| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:27:23:34 | After ... == ... [false] |
@@ -64,6 +65,7 @@ hasBranchEdge
6465
| Test.java:23:27:23:34 | ... == ... | Test.java:23:27:23:29 | len | Test.java:23:34:23:34 | 4 | true | true | Test.java:23:39:23:41 | { ... } |
6566
| Test.java:24:7:24:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | true | false | Test.java:25:7:25:16 | default |
6667
| Test.java:24:7:24:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | true | true | Test.java:24:12:24:14 | "g" |
68+
| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:7:29:34 | After case <Pattern> [no-match] |
6769
| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:7:29:34 | case <Pattern> |
6870
| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:19:29:19 | <anonymous local variable> |
6971
| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:26:29:33 | After ... == ... [false] |

shared/controlflow/codeql/controlflow/ControlFlowGraph.qll

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,28 +1200,6 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
12001200
n2.isAfterValue(boollit, any(BooleanSuccessor t | t.getValue() = boollit.getValue()))
12011201
)
12021202
or
1203-
exists(ExprStmt exprstmt |
1204-
n1.isBefore(exprstmt) and
1205-
n2.isBefore(exprstmt.getExpr())
1206-
// the `isAfter(exprstmt.getExpr())` to `isAfter(exprstmt)` case is handled by `propagatesValue` above.
1207-
)
1208-
or
1209-
exists(BlockStmt blockstmt |
1210-
n1.isBefore(blockstmt) and
1211-
n2.isBefore(blockstmt.getStmt(0))
1212-
or
1213-
not exists(blockstmt.getStmt(_)) and
1214-
n1.isBefore(blockstmt) and
1215-
n2.isAfter(blockstmt) and
1216-
not simpleLeafNode(blockstmt)
1217-
or
1218-
exists(int i |
1219-
n1.isAfter(blockstmt.getStmt(i)) and
1220-
n2.isBefore(blockstmt.getStmt(i + 1))
1221-
)
1222-
// the `isAfter(blockstmt.getLastStmt())` to `isAfter(blockstmt)` case is handled by `propagatesValue` above.
1223-
)
1224-
or
12251203
exists(IfStmt ifstmt |
12261204
n1.isBefore(ifstmt) and
12271205
n2.isBefore(ifstmt.getCondition())
@@ -1434,6 +1412,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
14341412
exists(int i |
14351413
n1.isAfterValue(getRankedCaseCfgOrder(switch, i),
14361414
any(MatchingSuccessor t | t.getValue() = false))
1415+
or
1416+
n1.isAfterFalse(getRankedCaseCfgOrder(switch, i).getGuard())
14371417
|
14381418
n2.isBefore(getRankedCaseCfgOrder(switch, i + 1))
14391419
or
@@ -1478,9 +1458,6 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
14781458
or
14791459
n1.isAfterTrue(case.getGuard()) and
14801460
n2 = beforeBody
1481-
or
1482-
n1.isAfterFalse(case.getGuard()) and
1483-
n2.isAfterValue(case, any(MatchingSuccessor t | t.getValue() = false))
14841461
)
14851462
)
14861463
or
@@ -1525,8 +1502,11 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
15251502
(
15261503
n1.isBefore(ast) and not exists(getRankedChild(ast, _)) and not simpleLeafNode(ast)
15271504
or
1528-
exists(int i |
1529-
n1.isAfter(getRankedChild(ast, i)) and not exists(getRankedChild(ast, i + 1))
1505+
exists(int i, AstNode last |
1506+
last = getRankedChild(ast, i) and
1507+
not exists(getRankedChild(ast, i + 1)) and
1508+
n1.isAfter(last) and
1509+
not propagatesValue(last, ast)
15301510
)
15311511
) and
15321512
(if postOrInOrder(ast) then n2.isIn(ast) else n2.isAfter(ast))

0 commit comments

Comments
 (0)