Skip to content

Commit afa4e79

Browse files
committed
Rust: Add support for more AST nodes to CFG contruction
1 parent 9061536 commit afa4e79

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ module CfgImpl = Make<Location, CfgInput>;
5959

6060
import CfgImpl
6161

62+
class AwaitExprTree extends StandardPostOrderTree instanceof AwaitExpr {
63+
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
64+
}
65+
6266
class BinaryOpExprTree extends StandardPostOrderTree instanceof BinaryOpExpr {
6367
BinaryOpExprTree() { super.getOp() != "&&" and super.getOp() != "||" }
6468

@@ -129,7 +133,8 @@ class LogicalAndBinaryOpExprTree extends PreOrderTree instanceof BinaryOpExpr {
129133
}
130134
}
131135

132-
class BlockExprTree extends StandardPostOrderTree instanceof BlockExpr {
136+
// NOTE: This covers both normal blocks, async blocks, and unsafe blocks
137+
class BaseBlockExprTree extends StandardPostOrderTree instanceof BlockExprBase {
133138
override ControlFlowTree getChildNode(int i) {
134139
result = super.getStatement(i)
135140
or
@@ -154,11 +159,16 @@ class BreakExprTree extends PostOrderTree instanceof BreakExpr {
154159
}
155160

156161
class CallExprTree extends StandardPostOrderTree instanceof CallExpr {
157-
override ControlFlowTree getChildNode(int i) { result = super.getArg(i) }
162+
override ControlFlowTree getChildNode(int i) {
163+
result = super.getCallee() and
164+
result = super.getArg(i + 1)
165+
}
158166
}
159167

160168
class ClosureExprTree extends LeafTree instanceof ClosureExpr { }
161169

170+
class ConstExprTree extends LeafTree instanceof ConstExpr { }
171+
162172
class ContinueExprTree extends LeafTree instanceof ContinueExpr { }
163173

164174
class ExprStmtTree extends StandardPostOrderTree instanceof ExprStmt {
@@ -239,6 +249,10 @@ class LoopExprTree extends PostOrderTree instanceof LoopExpr {
239249

240250
class PathExprTree extends LeafTree instanceof PathExpr { }
241251

252+
class RecordLitExprTree extends StandardPostOrderTree instanceof RecordLitExpr {
253+
override ControlFlowTree getChildNode(int i) { result = super.getField(i).getExpr() }
254+
}
255+
242256
class ReturnExprTree extends PostOrderTree instanceof ReturnExpr {
243257
override predicate propagatesAbnormal(AstNode child) { child = super.getExpr() }
244258

@@ -253,5 +267,15 @@ class ReturnExprTree extends PostOrderTree instanceof ReturnExpr {
253267
}
254268
}
255269

270+
class TupleExprTree extends StandardPostOrderTree instanceof TupleExpr {
271+
override ControlFlowTree getChildNode(int i) { result = super.getExpr(i) }
272+
}
273+
274+
class UnderscoreExprTree extends LeafTree instanceof UnderscoreExpr { }
275+
276+
class UnaryOpExprTree extends StandardPostOrderTree instanceof UnaryOpExpr {
277+
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
278+
}
279+
256280
// A leaf tree for unimplemented nodes in the AST.
257281
class UnimplementedTree extends LeafTree instanceof Unimplemented { }

0 commit comments

Comments
 (0)