Skip to content

Commit 7d31e0b

Browse files
committed
wip
1 parent 20ebba3 commit 7d31e0b

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,7 @@ module RustDataFlow implements InputSig<Location> {
577577

578578
pragma[nomagic]
579579
private predicate implicitBorrow(Node node1, Node node2, ReferenceContent c) {
580-
(
581-
node1 = node2.(ImplicitDerefNode).getBorrowInputNode()
582-
or
583-
node1 = node2.(ImplicitBorrowNode).getBorrowInputNode()
584-
) and
580+
node1 = node2.(ImplicitDerefBorrowNode).getBorrowInputNode() and
585581
exists(c)
586582
}
587583

@@ -596,8 +592,6 @@ module RustDataFlow implements InputSig<Location> {
596592
not TypeInference::implicitDerefChainBorrow(container, _, _) and
597593
result.asExpr() = container
598594
or
599-
result.(ImplicitBorrowNode).getNode() = container
600-
or
601595
result.(ImplicitDerefNode).isLast(container)
602596
)
603597
}

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,36 @@ class ImplicitDerefNodeState extends TImplicitDerefNodeState {
267267
}
268268
}
269269

270+
/**
271+
* A node used to represent implicit dereferencing/borrowing.
272+
*/
273+
abstract class ImplicitDerefBorrowNode extends Node {
274+
/**
275+
* Gets the node that should the predecessor in a reference store-step into this
276+
* node, if any.
277+
*/
278+
abstract Node getBorrowInputNode();
279+
280+
abstract AstNode getUnderlyingAstNode();
281+
282+
override CfgScope getCfgScope() { result = this.getUnderlyingAstNode().getEnclosingCfgScope() }
283+
284+
override Location getLocation() { result = this.getUnderlyingAstNode().getLocation() }
285+
}
286+
270287
/**
271288
* A node used to represent implicit dereferencing.
272289
*/
273-
class ImplicitDerefNode extends Node, TImplicitDerefNode {
290+
class ImplicitDerefNode extends ImplicitDerefBorrowNode, TImplicitDerefNode {
274291
AstNode n;
275292
DerefChain derefChain;
276293
ImplicitDerefNodeState state;
277294
int i;
278295

279296
ImplicitDerefNode() { this = TImplicitDerefNode(n, derefChain, state, i, false) }
280297

298+
override AstNode getUnderlyingAstNode() { result = n }
299+
281300
private predicate isNoOp() { derefChain.isNoOp(i) }
282301

283302
private Node getInputNode() {
@@ -297,11 +316,7 @@ class ImplicitDerefNode extends Node, TImplicitDerefNode {
297316
result = this.getInputNode()
298317
}
299318

300-
/**
301-
* Gets the node that should the predecessor in a reference store-step into this
302-
* node, if any.
303-
*/
304-
Node getBorrowInputNode() {
319+
override Node getBorrowInputNode() {
305320
not this.isNoOp() and
306321
state = TImplicitDerefNodeBorrowState() and
307322
result = this.getInputNode()
@@ -322,10 +337,6 @@ class ImplicitDerefNode extends Node, TImplicitDerefNode {
322337
i = derefChain.length() - 1
323338
}
324339

325-
override CfgScope getCfgScope() { result = n.getEnclosingCfgScope() }
326-
327-
override Location getLocation() { result = n.getLocation() }
328-
329340
override string toString() { result = n + " [implicit deref " + i + " in state " + state + "]" }
330341
}
331342

@@ -366,19 +377,15 @@ private class ImplicitDerefOutNode extends ImplicitDerefNode, OutNode {
366377
/**
367378
* A node that represents the value of an expression _after_ implicit borrowing.
368379
*/
369-
class ImplicitBorrowNode extends Node, TImplicitBorrowNode {
380+
class ImplicitBorrowNode extends ImplicitDerefBorrowNode, TImplicitBorrowNode {
370381
AstNode n;
371382
DerefChain derefChain;
372383

373384
ImplicitBorrowNode() { this = TImplicitBorrowNode(n, derefChain, false) }
374385

375-
AstNode getNode() { result = n }
386+
override AstNode getUnderlyingAstNode() { result = n }
376387

377-
/**
378-
* Gets the node that should the predecessor in a reference store-step into this
379-
* node.
380-
*/
381-
Node getBorrowInputNode() {
388+
override Node getBorrowInputNode() {
382389
result =
383390
TImplicitDerefNode(n, derefChain, TImplicitDerefNodeAfterDerefState(),
384391
derefChain.length() - 1, false)
@@ -387,10 +394,6 @@ class ImplicitBorrowNode extends Node, TImplicitBorrowNode {
387394
result.(AstNodeNode).getAstNode() = n
388395
}
389396

390-
override CfgScope getCfgScope() { result = n.getEnclosingCfgScope() }
391-
392-
override Location getLocation() { result = n.getLocation() }
393-
394397
override string toString() { result = n + " [implicit borrow]" }
395398
}
396399

0 commit comments

Comments
 (0)