Skip to content

Commit 8d59b92

Browse files
committed
Rust: Make improvements to data flow based on PR feedback
1 parent 2818893 commit 8d59b92

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ module Node {
9595

9696
final class ArgumentNode = NaNode;
9797

98+
/** An SSA node. */
99+
abstract class SsaNode extends Node, TSsaNode {
100+
SsaImpl::DataFlowIntegration::SsaNode node;
101+
SsaImpl::DefinitionExt def;
102+
103+
SsaNode() {
104+
this = TSsaNode(node) and
105+
def = node.getDefinitionExt()
106+
}
107+
108+
SsaImpl::DefinitionExt getDefinitionExt() { result = def }
109+
110+
/** Holds if this node should be hidden from path explanations. */
111+
abstract predicate isHidden();
112+
113+
override Location getLocation() { result = node.getLocation() }
114+
115+
override string toString() { result = node.toString() }
116+
}
117+
98118
final class ReturnNode extends NaNode {
99119
RustDataFlow::ReturnKind getKind() { none() }
100120
}
@@ -154,7 +174,7 @@ module SsaFlow {
154174
* For instance, the predicate holds for if expressions as `if b { e1 } else {
155175
* e2 }` evalates to the value of one of the subexpressions `e1` or `e2`.
156176
*/
157-
predicate propagatesValue(Expr e) {
177+
private predicate propagatesValue(Expr e) {
158178
e instanceof IfExpr or
159179
e instanceof LoopExpr or
160180
e instanceof ReturnExpr or

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,18 @@ class PhiReadNode extends DefinitionExt, Impl::PhiReadNode {
461461
}
462462

463463
private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInputSig {
464-
class Expr extends CfgNodes::ExprCfgNode {
464+
class Expr extends CfgNodes::AstCfgNode {
465465
predicate hasCfgNode(SsaInput::BasicBlock bb, int i) { this = bb.getNode(i) }
466466
}
467467

468468
Expr getARead(Definition def) { result = Cached::getARead(def) }
469469

470470
/** Holds if SSA definition `def` assigns `value` to the underlying variable. */
471-
predicate ssaDefAssigns(WriteDefinition def, Expr value) { none() }
471+
predicate ssaDefAssigns(WriteDefinition def, Expr value) {
472+
exists(CfgNode node, BasicBlock bb, int i |
473+
def.definesAt(_, bb, i) and value.getAstNode() = node.getAstNode().(AssignmentExpr).getLhs()
474+
)
475+
}
472476

473477
class Parameter = Param;
474478

0 commit comments

Comments
 (0)