Swift: Remove omittable exists variables

This commit is contained in:
Tony Torralba
2022-12-22 11:26:58 +01:00
parent 7ef8099a8b
commit 50cd40ed20
5 changed files with 39 additions and 47 deletions

View File

@@ -165,8 +165,8 @@ module Ssa {
class PhiDefinition extends Definition, SsaImpl::PhiNode { class PhiDefinition extends Definition, SsaImpl::PhiNode {
cached cached
override Location getLocation() { override Location getLocation() {
exists(SsaInput::BasicBlock bb, int i | exists(SsaInput::BasicBlock bb |
this.definesAt(_, bb, i) and this.definesAt(_, bb, _) and
result = bb.getLocation() result = bb.getLocation()
) )
} }

View File

@@ -876,9 +876,9 @@ private module Stage1 implements StageSig {
pragma[nomagic] pragma[nomagic]
private predicate revFlowOut(ReturnPosition pos, Configuration config) { private predicate revFlowOut(ReturnPosition pos, Configuration config) {
exists(DataFlowCall call, NodeEx out | exists(NodeEx out |
revFlow(out, _, config) and revFlow(out, _, config) and
viableReturnPosOutNodeCandFwd1(call, pos, out, config) viableReturnPosOutNodeCandFwd1(_, pos, out, config)
) )
} }
@@ -1731,8 +1731,8 @@ private module MkStage<StageSig PrevStage> {
) )
or or
// flow through a callable // flow through a callable
exists(DataFlowCall call, ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp | exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config) flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config)
) )
or or
@@ -1901,8 +1901,8 @@ private module MkStage<StageSig PrevStage> {
pragma[nomagic] pragma[nomagic]
predicate parameterMayFlowThrough(ParamNodeEx p, Ap ap, Configuration config) { predicate parameterMayFlowThrough(ParamNodeEx p, Ap ap, Configuration config) {
exists(RetNodeEx ret, ReturnPosition pos | exists(ReturnPosition pos |
returnFlowsThrough(ret, pos, _, _, p, ap, _, config) and returnFlowsThrough(_, pos, _, _, p, ap, _, config) and
parameterFlowsThroughRev(p, ap, pos, _, config) parameterFlowsThroughRev(p, ap, pos, _, config)
) )
} }
@@ -1923,8 +1923,8 @@ private module MkStage<StageSig PrevStage> {
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp, DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
Ap ap, Configuration config Ap ap, Configuration config
) { ) {
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp | exists(ParamNodeEx p, Ap innerReturnAp |
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config) flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config)
) )
} }
@@ -3749,8 +3749,8 @@ private predicate paramFlowsThrough(
ReturnKindExt kind, FlowState state, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, ReturnKindExt kind, FlowState state, CallContextCall cc, SummaryCtxSome sc, AccessPath ap,
AccessPathApprox apa, Configuration config AccessPathApprox apa, Configuration config
) { ) {
exists(PathNodeMid mid, RetNodeEx ret | exists(RetNodeEx ret |
pathNode(mid, ret, state, cc, sc, ap, config, _) and pathNode(_, ret, state, cc, sc, ap, config, _) and
kind = ret.getKind() and kind = ret.getKind() and
apa = ap.getApprox() and apa = ap.getApprox() and
parameterFlowThroughAllowed(sc.getParamNode(), kind) parameterFlowThroughAllowed(sc.getParamNode(), kind)
@@ -4212,17 +4212,15 @@ private module FlowExploration {
ap = TRevPartialNil() and ap = TRevPartialNil() and
exists(config.explorationLimit()) exists(config.explorationLimit())
or or
exists(PartialPathNodeRev mid | revPartialPathStep(_, node, state, sc1, sc2, sc3, ap, config) and
revPartialPathStep(mid, node, state, sc1, sc2, sc3, ap, config) and not clearsContentEx(node, ap.getHead()) and
not clearsContentEx(node, ap.getHead()) and (
( notExpectsContent(node) or
notExpectsContent(node) or expectsContentEx(node, ap.getHead())
expectsContentEx(node, ap.getHead()) ) and
) and not fullBarrier(node, config) and
not fullBarrier(node, config) and not stateBarrier(node, state, config) and
not stateBarrier(node, state, config) and distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
)
} }
pragma[nomagic] pragma[nomagic]
@@ -4230,19 +4228,17 @@ private module FlowExploration {
NodeEx node, FlowState state, CallContext cc, TSummaryCtx1 sc1, TSummaryCtx2 sc2, NodeEx node, FlowState state, CallContext cc, TSummaryCtx1 sc1, TSummaryCtx2 sc2,
TSummaryCtx3 sc3, PartialAccessPath ap, Configuration config TSummaryCtx3 sc3, PartialAccessPath ap, Configuration config
) { ) {
exists(PartialPathNodeFwd mid | partialPathStep(_, node, state, cc, sc1, sc2, sc3, ap, config) and
partialPathStep(mid, node, state, cc, sc1, sc2, sc3, ap, config) and not fullBarrier(node, config) and
not fullBarrier(node, config) and not stateBarrier(node, state, config) and
not stateBarrier(node, state, config) and not clearsContentEx(node, ap.getHead().getContent()) and
not clearsContentEx(node, ap.getHead().getContent()) and (
( notExpectsContent(node) or
notExpectsContent(node) or expectsContentEx(node, ap.getHead().getContent())
expectsContentEx(node, ap.getHead().getContent()) ) and
) and if node.asNode() instanceof CastingNode
if node.asNode() instanceof CastingNode then compatibleTypes(node.getDataFlowType(), ap.getType())
then compatibleTypes(node.getDataFlowType(), ap.getType()) else any()
else any()
)
} }
/** /**

View File

@@ -101,9 +101,7 @@ module Consistency {
exists(int c | exists(int c |
c = c =
strictcount(Node n | strictcount(Node n |
not exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | not n.hasLocationInfo(_, _, _, _, _) and
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
) and
not any(ConsistencyConfiguration conf).missingLocationExclude(n) not any(ConsistencyConfiguration conf).missingLocationExclude(n)
) and ) and
msg = "Nodes without location: " + c msg = "Nodes without location: " + c

View File

@@ -580,10 +580,8 @@ module Private {
head = TWithContentSummaryComponent(cont) head = TWithContentSummaryComponent(cont)
) )
or or
exists(ContentSet cont | head = TWithoutContentSummaryComponent(_) and
head = TWithoutContentSummaryComponent(cont) and result = getNodeType(summaryNodeInputState(c, s.tail()))
result = getNodeType(summaryNodeInputState(c, s.tail()))
)
or or
exists(ReturnKind rk | exists(ReturnKind rk |
head = TReturnSummaryComponent(rk) and head = TReturnSummaryComponent(rk) and
@@ -658,8 +656,8 @@ module Private {
/** Holds if summary node `ret` is a return node of kind `rk`. */ /** Holds if summary node `ret` is a return node of kind `rk`. */
predicate summaryReturnNode(Node ret, ReturnKind rk) { predicate summaryReturnNode(Node ret, ReturnKind rk) {
exists(SummarizedCallable callable, SummaryComponentStack s | exists(SummaryComponentStack s |
ret = summaryNodeOutputState(callable, s) and ret = summaryNodeOutputState(_, s) and
s = TSingletonSummaryComponentStack(TReturnSummaryComponent(rk)) s = TSingletonSummaryComponentStack(TReturnSummaryComponent(rk))
) )
} }

View File

@@ -32,12 +32,12 @@ class StaticInitializationVectorSource extends Expr {
class EncryptionInitializationSink extends Expr { class EncryptionInitializationSink extends Expr {
EncryptionInitializationSink() { EncryptionInitializationSink() {
// `iv` arg in `init` is a sink // `iv` arg in `init` is a sink
exists(InitializerCallExpr call, string fName | exists(InitializerCallExpr call |
call.getStaticTarget() call.getStaticTarget()
.hasQualifiedName([ .hasQualifiedName([
"AES", "ChaCha20", "Blowfish", "Rabbit", "CBC", "CFB", "GCM", "OCB", "OFB", "PCBC", "AES", "ChaCha20", "Blowfish", "Rabbit", "CBC", "CFB", "GCM", "OCB", "OFB", "PCBC",
"CCM", "CTR" "CCM", "CTR"
], fName) and ], _) and
call.getArgumentWithLabel("iv").getExpr() = this call.getArgumentWithLabel("iv").getExpr() = this
) )
} }