@@ -15,38 +15,40 @@ import codeql.rust.controlflow.internal.ControlFlowGraphImpl as ControlFlowGraph
15
15
/**
16
16
* Successor relation that includes unreachable AST nodes.
17
17
*/
18
- predicate succFull ( AstNode a , AstNode b ) {
18
+ private predicate succ ( AstNode a , AstNode b ) {
19
19
exists ( ControlFlowGraphImpl:: ControlFlowTree cft | cft .succ ( a , b , _) )
20
20
}
21
21
22
22
/**
23
- * Gets a node we'd prefer not to report as unreachable.
23
+ * Gets a node we'd prefer not to report as unreachable. These will be removed
24
+ * from the AST for the purposes of this query, with successor links being
25
+ * made across them where appropriate.
24
26
*/
25
- predicate skipNode ( AstNode n ) {
27
+ predicate hiddenNode ( AstNode n ) {
26
28
// isolated node (not intended to be part of the CFG)
27
- not succFull ( n , _) and
28
- not succFull ( _, n )
29
+ not succ ( n , _) and
30
+ not succ ( _, n )
29
31
or
30
32
n instanceof ControlFlowGraphImpl:: PostOrderTree // location is counter-intuitive
31
33
}
32
34
33
35
/**
34
- * Successor relation for edges out of `skipNode `s.
36
+ * Successor relation for edges out of `hiddenNode `s.
35
37
*/
36
- predicate succSkip ( AstNode a , AstNode b ) {
37
- skipNode ( a ) and
38
- succFull ( a , b )
38
+ private predicate succHidden ( AstNode a , AstNode b ) {
39
+ hiddenNode ( a ) and
40
+ succ ( a , b )
39
41
}
40
42
41
43
/**
42
- * Successor relation that skips over `skipNode `s.
44
+ * Successor relation that removes / links over `hiddenNode `s.
43
45
*/
44
- predicate succSkipping ( AstNode a , AstNode b ) {
46
+ private predicate succWithHiding ( AstNode a , AstNode b ) {
45
47
exists ( AstNode mid |
46
- not skipNode ( a ) and
47
- succFull ( a , mid ) and
48
- succSkip * ( mid , b ) and
49
- not skipNode ( b )
48
+ not hiddenNode ( a ) and
49
+ succ ( a , mid ) and
50
+ succHidden * ( mid , b ) and
51
+ not hiddenNode ( b )
50
52
)
51
53
}
52
54
@@ -61,8 +63,8 @@ predicate reachable(AstNode n) { n = any(CfgNode cfn).getAstNode() }
61
63
*/
62
64
private predicate firstUnreachable ( AstNode n ) {
63
65
not reachable ( n ) and
64
- not skipNode ( n ) and
65
- forall ( AstNode pred | succSkipping ( pred , n ) | reachable ( pred ) )
66
+ not hiddenNode ( n ) and
67
+ forall ( AstNode pred | succWithHiding ( pred , n ) | reachable ( pred ) )
66
68
}
67
69
68
70
from AstNode n
0 commit comments