Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions unified/ql/lib/codeql/unified/internal/FacadeAst.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module;
private import AstPlugin
private import codeql.files.FileSystem
private import codeql.unified.internal.NameBinding as NameBinding
private import codeql.unified.internal.ControlFlowGraph::Public

module Unified {
private import Ast::Unified as G
Expand Down Expand Up @@ -124,6 +125,12 @@ module Unified {
or
result = this.getParent().(Argument).getParent()
}

/** Gets the `ControlFlowNode` corresponding to this expression. */
ControlFlowNode getControlFlowNode() { result.injects(this) }

/** Gets the basic block containing this expression. */
BasicBlock getBasicBlock() { result = this.getControlFlowNode().getBasicBlock() }
}

class AccessorDeclaration extends G::AccessorDeclaration {
Expand Down
46 changes: 46 additions & 0 deletions unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,52 @@ module LocalSsaOutput = Make<Location, Cfg, LocalSsaInput>;

private import LocalSsaOutput

private module SsaInput implements SsaInputSig {
private import codeql.unified.internal.ExprPositions

class Expr = U::Expr;

class Parameter = U::Parameter;

class VariableWrite instanceof BuilderNode {
private AstNode writeAccess;

VariableWrite() { this.isLocalVariableWrite(writeAccess, _) }

Expr asExpr() { hasIncomingValue(writeAccess, result) }

Expr getValue() {
exists(VariableDeclaration decl |
writeAccess = decl.getPattern() and result = decl.getValue()
)
Comment on lines +56 to +58
or
exists(AssignExpr assignment |
writeAccess = assignment.getTarget() and result = assignment.getValue()
)
or
writeAccess = result.(CompoundAssignExpr).getTarget()
// TODO: Add case for prefix unary crement operations
}

predicate isParameterInit(Parameter p) { p.getPattern() = writeAccess }

string toString() { result = super.toString() }

Location getLocation() { result = super.getLocation() }
}

predicate explicitWrite(VariableWrite w, BasicBlock bb, int i, LocalSsaInput::SourceVariable v) {
exists(AstNode repr |
w.(BuilderNode).isLocalVariableWrite(repr, v) and
performsVariableAccess(repr, v, _, bb.getNode(i))
)
}
}

module SsaPublic {
module Ssa = MakeSsa<SsaInput>;
}

module LocalSsaDataFlowInput implements DataFlowIntegrationInputSig {
class Expr = LocalVariableRefNode;

Expand Down
1 change: 1 addition & 0 deletions unified/ql/lib/unified.qll
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ import codeql.unified.internal.AstExtra::Public
import codeql.unified.internal.ControlFlowGraph::Public
import codeql.unified.internal.NameBinding::Public
import codeql.unified.internal.dataflow.DataFlowPublic
import codeql.unified.internal.dataflow.LocalSsa::SsaPublic
import codeql.unified.internal.mad.LegacyMaD::Public
Loading