Skip to content
Open
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 @@ -9,6 +9,7 @@ private import AstPlugin
private import codeql.files.FileSystem
private import codeql.unified.internal.NameBinding as NameBinding
private import codeql.unified.internal.typeinference.TypeMention as TypeMention
private import codeql.unified.internal.ControlFlowGraph::Public

module Unified {
private import Ast::Unified as G
Expand Down Expand Up @@ -133,6 +134,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
52 changes: 52 additions & 0 deletions unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,58 @@ 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()
)
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))
)
}

predicate explicitRead(Expr e, LocalSsaInput::SourceVariable v) {
e.(LocalVariableAccess).getLocalVariable() = v and hasResultValue(e)
}
}

module SsaPublic {
module Ssa = MakeSsa<SsaInput>;
Comment thread
aschackmull marked this conversation as resolved.
Resolved

import Ssa
}

module LocalSsaDataFlowInput implements DataFlowIntegrationInputSig {
class GuardValue = Void;

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