mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Minor adjustments to SSA library for self variables
This commit is contained in:
committed by
Harry Maclean
parent
0d39a15786
commit
446eb13471
@@ -71,8 +71,11 @@ class ClassVariable extends Variable instanceof ClassVariableImpl {
|
||||
final override ClassVariableAccess getAnAccess() { result.getVariable() = this }
|
||||
}
|
||||
|
||||
/** The `self` variable */
|
||||
class SelfVariable extends Variable instanceof SelfVariableImpl { }
|
||||
/** A `self` variable. */
|
||||
class SelfVariable extends LocalVariable instanceof SelfVariableImpl {
|
||||
/** Gets the method that this `self` variable belongs to. */
|
||||
MethodBase getMethod() { result = this.getDeclaringScope() }
|
||||
}
|
||||
|
||||
/** An access to a variable. */
|
||||
class VariableAccess extends Expr instanceof VariableAccessImpl {
|
||||
|
||||
@@ -220,6 +220,19 @@ module Ssa {
|
||||
final override Location getLocation() { result = this.getControlFlowNode().getLocation() }
|
||||
}
|
||||
|
||||
/**
|
||||
* An SSA definition that corresponds to the value of `self` upon method entry.
|
||||
*/
|
||||
class SelfDefinition extends Definition, SsaImplCommon::WriteDefinition {
|
||||
private SelfVariable v;
|
||||
|
||||
SelfDefinition() { this.definesAt(v, _, _) }
|
||||
|
||||
final override string toString() { result = "self (" + v.getMethod() + ")" }
|
||||
|
||||
final override Location getLocation() { result = this.getControlFlowNode().getLocation() }
|
||||
}
|
||||
|
||||
/**
|
||||
* An SSA definition inserted at the beginning of a scope to represent an
|
||||
* uninitialized local variable. For example, in
|
||||
|
||||
@@ -7,7 +7,8 @@ private import CfgNodes::ExprNodes
|
||||
/** Holds if `v` is uninitialized at index `i` in entry block `bb`. */
|
||||
predicate uninitializedWrite(EntryBasicBlock bb, int i, LocalVariable v) {
|
||||
v.getDeclaringScope() = bb.getScope() and
|
||||
i = -1
|
||||
i = -1 and
|
||||
not v instanceof SelfVariable
|
||||
}
|
||||
|
||||
/** Holds if `bb` contains a caputured read of variable `v`. */
|
||||
|
||||
@@ -24,11 +24,8 @@ class SourceVariable = LocalVariable;
|
||||
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
|
||||
(
|
||||
// We consider the `self` variable to have a single write at the entry to a method block.
|
||||
exists(SelfVariableAccess access |
|
||||
access.getCfgScope() = bb.getScope() and
|
||||
access.getVariable() = v and
|
||||
i = 0
|
||||
)
|
||||
v.(SelfVariable).getDeclaringScope() = bb.(BasicBlocks::EntryBasicBlock).getScope() and
|
||||
i = 0
|
||||
or
|
||||
SsaImpl::uninitializedWrite(bb, i, v)
|
||||
or
|
||||
|
||||
Reference in New Issue
Block a user