mirror of
https://github.com/github/codeql.git
synced 2026-05-14 11:19:27 +02:00
C#: Replace most uses of Ssa::Definition with SsaDefinition.
This commit is contained in:
@@ -570,7 +570,7 @@ class AccessOrCallExpr extends Expr {
|
||||
* An expression can have more than one SSA qualifier in the presence
|
||||
* of control flow splitting.
|
||||
*/
|
||||
Ssa::Definition getAnSsaQualifier(ControlFlowNode cfn) { result = getAnSsaQualifier(this, cfn) }
|
||||
SsaDefinition getAnSsaQualifier(ControlFlowNode cfn) { result = getAnSsaQualifier(this, cfn) }
|
||||
}
|
||||
|
||||
private Declaration getDeclarationTarget(Expr e) {
|
||||
@@ -578,14 +578,14 @@ private Declaration getDeclarationTarget(Expr e) {
|
||||
result = e.(Call).getTarget()
|
||||
}
|
||||
|
||||
private Ssa::Definition getAnSsaQualifier(Expr e, ControlFlowNode cfn) {
|
||||
private SsaDefinition getAnSsaQualifier(Expr e, ControlFlowNode cfn) {
|
||||
e = getATrackedAccess(result, cfn)
|
||||
or
|
||||
not e = getATrackedAccess(_, _) and
|
||||
result = getAnSsaQualifier(e.(QualifiableExpr).getQualifier(), cfn)
|
||||
}
|
||||
|
||||
private AssignableAccess getATrackedAccess(Ssa::Definition def, ControlFlowNode cfn) {
|
||||
private AssignableAccess getATrackedAccess(SsaDefinition def, ControlFlowNode cfn) {
|
||||
result = def.getARead() and cfn = result.getControlFlowNode()
|
||||
or
|
||||
result = def.(Ssa::ExplicitDefinition).getADefinition().getTargetAccess() and
|
||||
@@ -593,7 +593,7 @@ private AssignableAccess getATrackedAccess(Ssa::Definition def, ControlFlowNode
|
||||
}
|
||||
|
||||
private predicate ssaMustHaveValue(Expr e, GuardValue v) {
|
||||
exists(Ssa::Definition def, BasicBlock bb |
|
||||
exists(SsaDefinition def, BasicBlock bb |
|
||||
e = def.getARead() and
|
||||
e.getBasicBlock() = bb and
|
||||
Guards::ssaControls(def, bb, v)
|
||||
@@ -825,8 +825,8 @@ module Internal {
|
||||
)
|
||||
or
|
||||
e =
|
||||
any(Ssa::Definition def |
|
||||
forex(Ssa::Definition u | u = def.getAnUltimateDefinition() | nullDef(u))
|
||||
any(SsaDefinition def |
|
||||
forex(SsaDefinition u | u = def.getAnUltimateDefinition() | nullDef(u))
|
||||
).getARead()
|
||||
}
|
||||
|
||||
@@ -840,8 +840,8 @@ module Internal {
|
||||
exists(Expr e1 | nonNullValueImplied(e1) and nonNullValueImpliedUnary(e1, e))
|
||||
or
|
||||
e =
|
||||
any(Ssa::Definition def |
|
||||
forex(Ssa::Definition u | u = def.getAnUltimateDefinition() | nonNullDef(u))
|
||||
any(SsaDefinition def |
|
||||
forex(SsaDefinition u | u = def.getAnUltimateDefinition() | nonNullDef(u))
|
||||
).getARead()
|
||||
}
|
||||
|
||||
@@ -1104,7 +1104,7 @@ module Internal {
|
||||
private predicate nodeIsGuardedBySameSubExprSsaDef0(
|
||||
ControlFlowNode cfn, BasicBlock guardedBB, AccessOrCallExpr guarded, Guard g,
|
||||
ControlFlowNode subCfn, BasicBlock subCfnBB, AccessOrCallExpr sub, GuardValue v,
|
||||
Ssa::Definition def
|
||||
SsaDefinition def
|
||||
) {
|
||||
nodeIsGuardedBySameSubExpr(cfn, guardedBB, guarded, g, sub, v) and
|
||||
def = sub.getAnSsaQualifier(subCfn) and
|
||||
@@ -1114,7 +1114,7 @@ module Internal {
|
||||
pragma[nomagic]
|
||||
private predicate nodeIsGuardedBySameSubExprSsaDef(
|
||||
ControlFlowNode guardedCfn, AccessOrCallExpr guarded, Guard g, ControlFlowNode subCfn,
|
||||
AccessOrCallExpr sub, GuardValue v, Ssa::Definition def
|
||||
AccessOrCallExpr sub, GuardValue v, SsaDefinition def
|
||||
) {
|
||||
exists(BasicBlock guardedBB, BasicBlock subCfnBB |
|
||||
nodeIsGuardedBySameSubExprSsaDef0(guardedCfn, guardedBB, guarded, g, subCfn, subCfnBB, sub,
|
||||
@@ -1133,7 +1133,7 @@ module Internal {
|
||||
cached
|
||||
predicate isGuardedByExpr(AccessOrCallExpr guarded, Guard g, AccessOrCallExpr sub, GuardValue v) {
|
||||
isGuardedByExpr0(guarded, g, sub, v) and
|
||||
forall(ControlFlowNode subCfn, Ssa::Definition def |
|
||||
forall(ControlFlowNode subCfn, SsaDefinition def |
|
||||
nodeIsGuardedBySameSubExprSsaDef(_, guarded, g, subCfn, sub, v, def)
|
||||
|
|
||||
def = guarded.getAnSsaQualifier(_)
|
||||
@@ -1145,7 +1145,7 @@ module Internal {
|
||||
ControlFlowNodes::ElementNode guarded, Guard g, AccessOrCallExpr sub, GuardValue v
|
||||
) {
|
||||
nodeIsGuardedBySameSubExpr(guarded, _, _, g, sub, v) and
|
||||
forall(ControlFlowNode subCfn, Ssa::Definition def |
|
||||
forall(ControlFlowNode subCfn, SsaDefinition def |
|
||||
nodeIsGuardedBySameSubExprSsaDef(guarded, _, g, subCfn, sub, v, def)
|
||||
|
|
||||
def =
|
||||
|
||||
@@ -67,8 +67,8 @@ class AlwaysNullExpr extends Expr {
|
||||
exists(AlwaysNullExpr e1, AlwaysNullExpr e2 | G::Internal::nullValueImpliedBinary(e1, e2, this))
|
||||
or
|
||||
this =
|
||||
any(Ssa::Definition def |
|
||||
forex(Ssa::Definition u | u = def.getAnUltimateDefinition() | nullDef(u))
|
||||
any(SsaDefinition def |
|
||||
forex(SsaDefinition u | u = def.getAnUltimateDefinition() | nullDef(u))
|
||||
).getARead()
|
||||
or
|
||||
exists(Callable target |
|
||||
@@ -94,8 +94,8 @@ class NonNullExpr extends Expr {
|
||||
this instanceof G::NullGuardedExpr
|
||||
or
|
||||
this =
|
||||
any(Ssa::Definition def |
|
||||
forex(Ssa::Definition u | u = def.getAnUltimateDefinition() | nonNullDef(u))
|
||||
any(SsaDefinition def |
|
||||
forex(SsaDefinition u | u = def.getAnUltimateDefinition() | nonNullDef(u))
|
||||
).getARead()
|
||||
or
|
||||
exists(Callable target |
|
||||
@@ -126,7 +126,7 @@ private predicate nonNullDef(Ssa::ExplicitDefinition def) {
|
||||
/**
|
||||
* Holds if `d` is a dereference of SSA definition `def`.
|
||||
*/
|
||||
private predicate dereferenceAt(Ssa::Definition def, Dereference d) { d = def.getARead() }
|
||||
private predicate dereferenceAt(SsaDefinition def, Dereference d) { d = def.getARead() }
|
||||
|
||||
private predicate isMaybeNullArgument(Ssa::ParameterDefinition def, MaybeNullExpr arg) {
|
||||
exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p |
|
||||
@@ -180,7 +180,7 @@ private predicate hasMultipleParamsArguments(Call c) {
|
||||
}
|
||||
|
||||
/** Holds if `def` is an SSA definition that may be `null`. */
|
||||
private predicate defMaybeNull(Ssa::Definition def, ControlFlowNode node, string msg, Element reason) {
|
||||
private predicate defMaybeNull(SsaDefinition def, ControlFlowNode node, string msg, Element reason) {
|
||||
not nonNullDef(def) and
|
||||
(
|
||||
// A variable compared to `null` might be `null`
|
||||
@@ -222,13 +222,13 @@ private predicate defMaybeNull(Ssa::Definition def, ControlFlowNode node, string
|
||||
)
|
||||
}
|
||||
|
||||
private Ssa::Definition getAPseudoInput(Ssa::Definition def) {
|
||||
private SsaDefinition getAPseudoInput(SsaDefinition def) {
|
||||
result = def.(Ssa::PhiNode).getAnInput()
|
||||
}
|
||||
|
||||
// `def.getAnUltimateDefinition()` includes inputs into uncertain
|
||||
// definitions, but we only want inputs into pseudo nodes
|
||||
private Ssa::Definition getAnUltimateDefinition(Ssa::Definition def) {
|
||||
private SsaDefinition getAnUltimateDefinition(SsaDefinition def) {
|
||||
result = getAPseudoInput*(def) and
|
||||
not result instanceof Ssa::PhiNode
|
||||
}
|
||||
@@ -238,7 +238,7 @@ private Ssa::Definition getAnUltimateDefinition(Ssa::Definition def) {
|
||||
* through an intermediate dereference that always throws a null reference
|
||||
* exception.
|
||||
*/
|
||||
private predicate defReaches(Ssa::Definition def, ControlFlowNode cfn) {
|
||||
private predicate defReaches(SsaDefinition def, ControlFlowNode cfn) {
|
||||
Ssa::ssaGetAFirstUse(def).getControlFlowNode() = cfn
|
||||
or
|
||||
exists(ControlFlowNode mid | defReaches(def, mid) |
|
||||
@@ -266,7 +266,7 @@ private module NullnessConfig implements ControlFlowReachability::ConfigSig {
|
||||
private module NullnessFlow = ControlFlowReachability::Flow<NullnessConfig>;
|
||||
|
||||
predicate maybeNullDeref(Dereference d, Ssa::SourceVariable v, string msg, Element reason) {
|
||||
exists(Ssa::Definition origin, Ssa::Definition ssa, ControlFlowNode src, ControlFlowNode sink |
|
||||
exists(SsaDefinition origin, SsaDefinition ssa, ControlFlowNode src, ControlFlowNode sink |
|
||||
defMaybeNull(origin, src, msg, reason) and
|
||||
NullnessFlow::flow(src, origin, sink, ssa) and
|
||||
ssa.getSourceVariable() = v and
|
||||
@@ -334,8 +334,8 @@ class Dereference extends G::DereferenceableExpr {
|
||||
)
|
||||
}
|
||||
|
||||
private predicate isAlwaysNull0(Ssa::Definition def) {
|
||||
forall(Ssa::Definition input | input = getAnUltimateDefinition(def) |
|
||||
private predicate isAlwaysNull0(SsaDefinition def) {
|
||||
forall(SsaDefinition input | input = getAnUltimateDefinition(def) |
|
||||
input.(Ssa::ExplicitDefinition).getADefinition().getSource() instanceof AlwaysNullExpr
|
||||
) and
|
||||
not nonNullDef(def) and
|
||||
@@ -352,7 +352,7 @@ class Dereference extends G::DereferenceableExpr {
|
||||
// Exclude fields and properties, as they may not have an accurate SSA representation
|
||||
v.getAssignable() instanceof LocalScopeVariable and
|
||||
(
|
||||
forex(Ssa::Definition def0 | this = def0.getARead() | this.isAlwaysNull0(def0))
|
||||
forex(SsaDefinition def0 | this = def0.getARead() | this.isAlwaysNull0(def0))
|
||||
or
|
||||
exists(G::GuardValue nv |
|
||||
this.(G::GuardedExpr).mustHaveValue(nv) and
|
||||
|
||||
@@ -270,7 +270,7 @@ module VariableCapture {
|
||||
private predicate closureFlowStep(ControlFlowNodes::ExprNode e1, ControlFlowNodes::ExprNode e2) {
|
||||
e1.getExpr() = LocalFlow::getALastEvalNode(e2.getExpr())
|
||||
or
|
||||
exists(Ssa::Definition def, AssignableDefinition adef |
|
||||
exists(SsaDefinition def, AssignableDefinition adef |
|
||||
LocalFlow::defAssigns(adef, _, _, e1) and
|
||||
def.getAnUltimateDefinition().(Ssa::ExplicitDefinition).getADefinition() = adef and
|
||||
def.getARead().getControlFlowNode() = e2
|
||||
@@ -2016,7 +2016,7 @@ private class FieldOrPropertyRead extends FieldOrPropertyAccess, AssignableRead
|
||||
* SSA updates.
|
||||
*/
|
||||
predicate hasNonlocalValue() {
|
||||
exists(Ssa::Definition def, Ssa::ImplicitDefinition idef |
|
||||
exists(SsaDefinition def, Ssa::ImplicitDefinition idef |
|
||||
def.getARead() = this and
|
||||
idef = def.getAnUltimateDefinition()
|
||||
|
|
||||
|
||||
@@ -915,9 +915,9 @@ private module Cached {
|
||||
}
|
||||
|
||||
cached
|
||||
predicate isLiveOutRefParameterDefinition(Ssa::Definition def, Parameter p) {
|
||||
predicate isLiveOutRefParameterDefinition(SsaDefinition def, Parameter p) {
|
||||
p.isOutOrRef() and
|
||||
exists(Ssa::SourceVariable v, Ssa::Definition def0, BasicBlock bb, int i |
|
||||
exists(Ssa::SourceVariable v, SsaDefinition def0, BasicBlock bb, int i |
|
||||
v = def.getSourceVariable() and
|
||||
p = v.getAssignable() and
|
||||
def = def0.getAnUltimateDefinition() and
|
||||
|
||||
@@ -106,7 +106,7 @@ private module Impl {
|
||||
* - `isEq = true` : `def == e + delta`
|
||||
* - `isEq = false` : `def != e + delta`
|
||||
*/
|
||||
Guard eqFlowCond(Definition def, ExprNode e, int delta, boolean isEq, boolean testIsTrue) {
|
||||
Guard eqFlowCond(SsaDefinition def, ExprNode e, int delta, boolean isEq, boolean testIsTrue) {
|
||||
exists(boolean eqpolarity |
|
||||
result.isEquality(ssaRead(def, delta), e, eqpolarity) and
|
||||
testIsTrue = [false, true] and
|
||||
|
||||
@@ -13,7 +13,7 @@ module Private {
|
||||
|
||||
class ConstantIntegerExpr = CU::ConstantIntegerExpr;
|
||||
|
||||
class SsaVariable = CS::Ssa::Definition;
|
||||
class SsaVariable = CS::SsaDefinition;
|
||||
|
||||
class SsaPhiNode = CS::Ssa::PhiNode;
|
||||
|
||||
@@ -245,7 +245,7 @@ private module Impl {
|
||||
)
|
||||
}
|
||||
|
||||
ExprNode getARead(Ssa::Definition v) { v.getARead().getControlFlowNode() = result }
|
||||
ExprNode getARead(SsaDefinition v) { v.getARead().getControlFlowNode() = result }
|
||||
|
||||
Field getField(ExprNode fa) { result = fa.getExpr().(FieldAccess).getTarget() }
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
private import csharp as CS
|
||||
private import SsaReadPositionCommon
|
||||
|
||||
class SsaVariable = CS::Ssa::Definition;
|
||||
class SsaVariable = CS::SsaDefinition;
|
||||
|
||||
class SsaPhiNode = CS::Ssa::PhiNode;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ private import ConstantUtils
|
||||
private class ExprNode = ControlFlowNodes::ExprNode;
|
||||
|
||||
/** An SSA variable. */
|
||||
class SsaVariable extends Definition {
|
||||
class SsaVariable extends SsaDefinition {
|
||||
/** Gets a read of this SSA variable. */
|
||||
ExprNode getAUse() { this.getARead().getControlFlowNode() = result }
|
||||
}
|
||||
@@ -26,7 +26,7 @@ ExprNode getAnExplicitDefinitionRead(ExprNode src) {
|
||||
/**
|
||||
* Gets an expression that equals `v - delta`.
|
||||
*/
|
||||
ExprNode ssaRead(Definition v, int delta) {
|
||||
ExprNode ssaRead(SsaDefinition v, int delta) {
|
||||
v.getARead().getControlFlowNode() = result and delta = 0
|
||||
or
|
||||
exists(ExprNode::AddOperation add, int d1, ConstantIntegerExpr c |
|
||||
|
||||
@@ -20,7 +20,7 @@ import semmle.code.csharp.controlflow.Guards as Guards
|
||||
import codeql.controlflow.queries.ConstantCondition as ConstCond
|
||||
|
||||
module ConstCondInput implements ConstCond::InputSig<BasicBlock> {
|
||||
class SsaDefinition = Ssa::Definition;
|
||||
class SsaDefinition = Ssa::SsaDefinition;
|
||||
|
||||
class GuardValue = Guards::GuardValue;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ abstract class BadDynamicCall extends DynamicExpr {
|
||||
}
|
||||
|
||||
private Type possibleTypeForRelevantSource(Variable v, int i, Expr source) {
|
||||
exists(AssignableRead read, Ssa::Definition ssaDef, Ssa::ExplicitDefinition ultimateSsaDef |
|
||||
exists(AssignableRead read, SsaDefinition ssaDef, Ssa::ExplicitDefinition ultimateSsaDef |
|
||||
read = this.getARelevantVariableAccess(i) and
|
||||
v = read.getTarget() and
|
||||
result = source.getType() and
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import csharp
|
||||
|
||||
from AssignableDefinition def, AssignableRead read, Ssa::Definition ult, Ssa::Definition ssaDef
|
||||
from AssignableDefinition def, AssignableRead read, SsaDefinition ult, SsaDefinition ssaDef
|
||||
where
|
||||
ssaDef.getAnUltimateDefinition() = ult and
|
||||
(
|
||||
|
||||
@@ -29,7 +29,7 @@ predicate defUsePair(AssignableDefinition def, AssignableRead read) {
|
||||
}
|
||||
|
||||
private LocalScopeVariableRead getAReachableUncertainRead(AssignableDefinition def) {
|
||||
exists(Ssa::Definition ssaDef |
|
||||
exists(SsaDefinition ssaDef |
|
||||
def = ssaDef.getAnUltimateDefinition().(Ssa::ExplicitDefinition).getADefinition()
|
||||
|
|
||||
result = ssaDef.getARead()
|
||||
|
||||
@@ -23,7 +23,7 @@ predicate parameterUsePair(Parameter p, AssignableRead read) {
|
||||
private LocalScopeVariableRead getAReachableUncertainRead(
|
||||
AssignableDefinitions::ImplicitParameterDefinition p
|
||||
) {
|
||||
exists(Ssa::Definition ssaDef |
|
||||
exists(SsaDefinition ssaDef |
|
||||
p.getParameter() = ssaDef.getAnUltimateDefinition().(Ssa::ParameterDefinition).getParameter()
|
||||
|
|
||||
result = ssaDef.getARead()
|
||||
|
||||
@@ -25,14 +25,14 @@ predicate useUsePair(LocalScopeVariableRead read1, LocalScopeVariableRead read2)
|
||||
|
||||
private newtype TLocalScopeVariableReadOrSsaDef =
|
||||
TLocalScopeVariableRead(LocalScopeVariableRead read) or
|
||||
TSsaDefinition(Ssa::Definition ssaDef)
|
||||
TSsaDefinition(SsaDefinition ssaDef)
|
||||
|
||||
private TLocalScopeVariableReadOrSsaDef getANextReadOrDef(TLocalScopeVariableReadOrSsaDef prev) {
|
||||
exists(LocalScopeVariableRead read | prev = TLocalScopeVariableRead(read) |
|
||||
result = TLocalScopeVariableRead(read.getANextRead())
|
||||
or
|
||||
not exists(read.getANextRead()) and
|
||||
exists(Ssa::Definition ssaDef, Ssa::PhiNode phi, BasicBlock bb |
|
||||
exists(SsaDefinition ssaDef, Ssa::PhiNode phi, BasicBlock bb |
|
||||
ssaDef.getARead() = read and
|
||||
phi.getAnInput() = ssaDef and
|
||||
phi.definesAt(_, bb, _) and
|
||||
@@ -41,7 +41,7 @@ private TLocalScopeVariableReadOrSsaDef getANextReadOrDef(TLocalScopeVariableRea
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(Ssa::Definition ssaDef | prev = TSsaDefinition(ssaDef) |
|
||||
exists(SsaDefinition ssaDef | prev = TSsaDefinition(ssaDef) |
|
||||
result = TLocalScopeVariableRead(Ssa::ssaGetAFirstUse(ssaDef))
|
||||
or
|
||||
not exists(Ssa::ssaGetAFirstUse(ssaDef)) and
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import csharp
|
||||
|
||||
from Ssa::SourceVariable v, Ssa::PhiNode phi, Ssa::Definition input
|
||||
from Ssa::SourceVariable v, Ssa::PhiNode phi, SsaDefinition input
|
||||
where
|
||||
phi.getAnInput() = input and
|
||||
v = phi.getSourceVariable()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import csharp
|
||||
|
||||
from Ssa::SourceVariable v, Ssa::Definition def
|
||||
from Ssa::SourceVariable v, SsaDefinition def
|
||||
where v = def.getSourceVariable()
|
||||
select v, def
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import csharp
|
||||
|
||||
from Ssa::SourceVariable v, Ssa::Definition def, AssignableRead read
|
||||
from Ssa::SourceVariable v, SsaDefinition def, AssignableRead read
|
||||
where
|
||||
read = def.getARead() and
|
||||
v = def.getSourceVariable()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import csharp
|
||||
|
||||
from Ssa::SourceVariable v, Ssa::Definition def, Ssa::Definition u
|
||||
from Ssa::SourceVariable v, SsaDefinition def, SsaDefinition u
|
||||
where
|
||||
u = def.getAnUltimateDefinition() and
|
||||
v = def.getSourceVariable()
|
||||
|
||||
Reference in New Issue
Block a user