Skip to content

Commit e81c348

Browse files
committed
Rust: Apply suggestions from PR comments
1 parent fffeac6 commit e81c348

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ module Node {
187187
* The value of a parameter at function entry, viewed as a node in a data
188188
* flow graph.
189189
*/
190-
final class NormalParameterNode extends ParameterNode, TParameterNode {
190+
final class PositionalParameterNode extends ParameterNode, TParameterNode {
191191
override ParamCfgNode n;
192192

193-
NormalParameterNode() { this = TParameterNode(n) }
193+
PositionalParameterNode() { this = TParameterNode(n) }
194194

195195
/** Gets the parameter in the CFG that this node corresponds to. */
196196
ParamCfgNode getParameter() { result = n }
@@ -230,10 +230,7 @@ module Node {
230230

231231
/** A data flow node that represents a value returned by a callable. */
232232
final class ReturnNode extends ExprNode {
233-
ReturnNode() {
234-
this.getCfgNode().getASuccessor() instanceof ExitCfgNode or
235-
this.getCfgNode().getASuccessor() instanceof AnnotatedExitCfgNode
236-
}
233+
ReturnNode() { this.getCfgNode().getASuccessor() instanceof AnnotatedExitCfgNode }
237234

238235
ReturnKind getKind() { any() }
239236
}
@@ -270,11 +267,11 @@ module Node {
270267
/** Gets the node before the state update. */
271268
Node getPreUpdateNode() { result = TExprNode(n) }
272269

273-
final override CfgScope getCfgScope() { result = n.getAstNode().getEnclosingCfgScope() }
270+
final override CfgScope getCfgScope() { result = n.getScope() }
274271

275-
final override Location getLocation() { result = n.getAstNode().getLocation() }
272+
final override Location getLocation() { result = n.getLocation() }
276273

277-
final override string toString() { result = n.getAstNode().toString() }
274+
final override string toString() { result = n.toString() }
278275
}
279276

280277
final class CastNode = NaNode;
@@ -287,7 +284,7 @@ module SsaFlow {
287284
private module SsaFlow = SsaImpl::DataFlowIntegration;
288285

289286
private Node::ParameterNode toParameterNode(ParamCfgNode p) {
290-
result.(Node::NormalParameterNode).getParameter() = p
287+
result.(Node::PositionalParameterNode).getParameter() = p
291288
}
292289

293290
/** Converts a control flow node into an SSA control flow node. */
@@ -336,7 +333,8 @@ module LocalFlow {
336333
nodeFrom.(Node::AstCfgFlowNode).getCfgNode() =
337334
nodeTo.(Node::SsaNode).getDefinitionExt().(Ssa::WriteDefinition).getControlFlowNode()
338335
or
339-
nodeFrom.(Node::NormalParameterNode).getParameter().getPat() = nodeTo.(Node::PatNode).getPat()
336+
nodeFrom.(Node::PositionalParameterNode).getParameter().getPat() =
337+
nodeTo.(Node::PatNode).getPat()
340338
or
341339
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
342340
or
@@ -376,7 +374,7 @@ module RustDataFlow implements InputSig<Location> {
376374

377375
/** Holds if `p` is a parameter of `c` at the position `pos`. */
378376
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {
379-
p.getCfgNode().getAstNode() = pos.getParameterIn(c.asCfgScope().(Function).getParamList())
377+
p.getCfgNode().getAstNode() = pos.getParameterIn(c.asCfgScope().(Callable).getParamList())
380378
}
381379

382380
/** Holds if `n` is an argument of `c` at the position `pos`. */
@@ -590,7 +588,7 @@ private module Cached {
590588
cached
591589
newtype TParameterPosition =
592590
TPositionalParameterPosition(int i) {
593-
exists(any(ParamList l).getParam(i)) or exists(any(ArgList l).getArg(i))
591+
i in [0 .. max([any(ParamList l).getNumberOfParams(), any(ArgList l).getNumberOfArgs()]) - 1]
594592
} or
595593
TSelfParameterPosition()
596594
}

rust/ql/test/library-tests/dataflow/global/inline-flow.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ subpaths
6464
| main.rs:41:26:44:5 | BlockExpr : unit | main.rs:30:17:30:22 | Param : unit | main.rs:30:32:32:1 | BlockExpr : unit | main.rs:41:13:44:6 | CallExpr : unit |
6565
| main.rs:90:29:90:29 | a : unit | main.rs:66:28:66:33 | Param : unit | main.rs:66:43:72:5 | BlockExpr : unit | main.rs:90:13:90:30 | ... .data_through(...) : unit |
6666
testFailures
67-
| main.rs:45:10:45:10 | a | Fixed missing result: hasValueFlow=14 |
6867
#select
6968
| main.rs:18:10:18:10 | a | main.rs:13:5:13:13 | CallExpr : unit | main.rs:18:10:18:10 | a | $@ | main.rs:13:5:13:13 | CallExpr : unit | CallExpr : unit |
7069
| main.rs:22:10:22:10 | n | main.rs:26:13:26:21 | CallExpr : unit | main.rs:22:10:22:10 | n | $@ | main.rs:26:13:26:21 | CallExpr : unit | CallExpr : unit |

rust/ql/test/library-tests/dataflow/global/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn block_expression_as_argument() {
4242
println!("Hello");
4343
source(14)
4444
});
45-
sink(a); // $ MISSING: hasValueFlow=14
45+
sink(a); // $ hasValueFlow=14
4646
}
4747

4848
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)