@@ -15,38 +15,40 @@ import codeql.rust.controlflow.internal.ControlFlowGraphImpl as ControlFlowGraph
1515/**
1616 * Successor relation that includes unreachable AST nodes.
1717 */
18- predicate succFull ( AstNode a , AstNode b ) {
18+ private predicate succ ( AstNode a , AstNode b ) {
1919 exists ( ControlFlowGraphImpl:: ControlFlowTree cft | cft .succ ( a , b , _) )
2020}
2121
2222/**
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.
2426 */
25- predicate skipNode ( AstNode n ) {
27+ predicate hiddenNode ( AstNode n ) {
2628 // 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 )
2931 or
3032 n instanceof ControlFlowGraphImpl:: PostOrderTree // location is counter-intuitive
3133}
3234
3335/**
34- * Successor relation for edges out of `skipNode `s.
36+ * Successor relation for edges out of `hiddenNode `s.
3537 */
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 )
3941}
4042
4143/**
42- * Successor relation that skips over `skipNode `s.
44+ * Successor relation that removes / links over `hiddenNode `s.
4345 */
44- predicate succSkipping ( AstNode a , AstNode b ) {
46+ private predicate succWithHiding ( AstNode a , AstNode b ) {
4547 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 )
5052 )
5153}
5254
@@ -61,8 +63,8 @@ predicate reachable(AstNode n) { n = any(CfgNode cfn).getAstNode() }
6163 */
6264private predicate firstUnreachable ( AstNode n ) {
6365 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 ) )
6668}
6769
6870from AstNode n
0 commit comments