Skip to content

Commit fb62e7a

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

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

Lines changed: 11 additions & 10 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 }
@@ -231,7 +231,7 @@ module Node {
231231
/** A data flow node that represents a value returned by a callable. */
232232
final class ReturnNode extends ExprNode {
233233
ReturnNode() {
234-
this.getCfgNode().getASuccessor() instanceof ExitCfgNode or
234+
// this.getCfgNode().getASuccessor() instanceof ExitCfgNode or
235235
this.getCfgNode().getASuccessor() instanceof AnnotatedExitCfgNode
236236
}
237237

@@ -270,11 +270,11 @@ module Node {
270270
/** Gets the node before the state update. */
271271
Node getPreUpdateNode() { result = TExprNode(n) }
272272

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

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

277-
final override string toString() { result = n.getAstNode().toString() }
277+
final override string toString() { result = n.toString() }
278278
}
279279

280280
final class CastNode = NaNode;
@@ -287,7 +287,7 @@ module SsaFlow {
287287
private module SsaFlow = SsaImpl::DataFlowIntegration;
288288

289289
private Node::ParameterNode toParameterNode(ParamCfgNode p) {
290-
result.(Node::NormalParameterNode).getParameter() = p
290+
result.(Node::PositionalParameterNode).getParameter() = p
291291
}
292292

293293
/** Converts a control flow node into an SSA control flow node. */
@@ -336,7 +336,8 @@ module LocalFlow {
336336
nodeFrom.(Node::AstCfgFlowNode).getCfgNode() =
337337
nodeTo.(Node::SsaNode).getDefinitionExt().(Ssa::WriteDefinition).getControlFlowNode()
338338
or
339-
nodeFrom.(Node::NormalParameterNode).getParameter().getPat() = nodeTo.(Node::PatNode).getPat()
339+
nodeFrom.(Node::PositionalParameterNode).getParameter().getPat() =
340+
nodeTo.(Node::PatNode).getPat()
340341
or
341342
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
342343
or
@@ -376,7 +377,7 @@ module RustDataFlow implements InputSig<Location> {
376377

377378
/** Holds if `p` is a parameter of `c` at the position `pos`. */
378379
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {
379-
p.getCfgNode().getAstNode() = pos.getParameterIn(c.asCfgScope().(Function).getParamList())
380+
p.getCfgNode().getAstNode() = pos.getParameterIn(c.asCfgScope().(Callable).getParamList())
380381
}
381382

382383
/** Holds if `n` is an argument of `c` at the position `pos`. */
@@ -590,7 +591,7 @@ private module Cached {
590591
cached
591592
newtype TParameterPosition =
592593
TPositionalParameterPosition(int i) {
593-
exists(any(ParamList l).getParam(i)) or exists(any(ArgList l).getArg(i))
594+
i in [0 .. max([any(ParamList l).getNumberOfParams(), any(ArgList l).getNumberOfArgs()]) - 1]
594595
} or
595596
TSelfParameterPosition()
596597
}

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)